-
-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean cancel #843
base: main
Are you sure you want to change the base?
Clean cancel #843
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -246,6 +246,13 @@ export class PageInternal extends PureComponent { | |||||
return { page: null }; | ||||||
}); | ||||||
|
||||||
// eslint-disable-next-line no-underscore-dangle | ||||||
if (pdf && pdf._transport && pdf._transport.destroyed) { | ||||||
this.setState({ page: false }); | ||||||
this.onLoadError('Attempted to load a page, but the document was destroyed'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed it |
||||||
return; | ||||||
} | ||||||
|
||||||
const cancellable = makeCancellable(pdf.getPage(pageNumber)); | ||||||
this.runningTask = cancellable; | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,9 +141,8 @@ export function isCancelException(error) { | |
} | ||
|
||
export function loadFromFile(file) { | ||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
|
||
const reader = new FileReader(); | ||
const promise = new Promise((resolve, reject) => { | ||
reader.onload = () => resolve(new Uint8Array(reader.result)); | ||
reader.onerror = (event) => { | ||
switch (event.target.error.code) { | ||
|
@@ -163,4 +162,11 @@ export function loadFromFile(file) { | |
|
||
return null; | ||
}); | ||
|
||
return { | ||
promise, | ||
abort: () => { | ||
reader.abort(); | ||
}, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering, if perhaps making the API consistent with make-cancelable-promise by changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both ok for me. I am thinking: 'cancel' is something like "I did the request, but I don't want it anymore, don't send what ever you have, no matter if finished or not" (which is what cancelable-promise does). "Abort" on the other hand is "Stop what you are doing right now". But from our perspective I guess what we want indeed is the same in both cases: don't call any callbacks. So 'cancel' would make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed it in an extra commit |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of this formatting inconsistency, but honestly, that should have been linter's job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed it