Immediately call onCancel handlers when a promise is canceled#24
Merged
sindresorhus merged 2 commits intosindresorhus:mainfrom Mar 10, 2021
Merged
Immediately call onCancel handlers when a promise is canceled#24sindresorhus merged 2 commits intosindresorhus:mainfrom
onCancel handlers when a promise is canceled#24sindresorhus merged 2 commits intosindresorhus:mainfrom
Conversation
szmarczak
reviewed
Jul 12, 2020
index.js
Outdated
| } | ||
|
|
||
| this._cancelHandlers.push(handler); | ||
| const fn = (...args) => { |
Contributor
There was a problem hiding this comment.
Can you undo this change? A much better solution is to move the this._isCanceled = true; before the if here:
szmarczak
reviewed
Jul 12, 2020
index.js
Outdated
| const onResolve = value => { | ||
| this._isPending = false; | ||
| resolve(value); | ||
| if (this._isCanceled !== true || onCancel.shouldReject === false) { |
Contributor
There was a problem hiding this comment.
Suggested change
| if (this._isCanceled !== true || onCancel.shouldReject === false) { | |
| if (!this._isCanceled || !onCancel.shouldReject) { |
Contributor
|
Add a test: test('throws immediately as soon as .cancel() is called', async t => {
const cancelablePromise = new PCancelable((resolve, reject, onCancel) => {
const timeout = setTimeout(() => {
resolve(true);
}, 10);
onCancel.shouldReject = true;
onCancel(() => {
clearTimeout(timeout);
resolve(false);
});
});
cancelablePromise.cancel();
await t.throwsAsync(cancelablePromise, {
message: 'Promise was canceled'
});
}); |
|
Is this still being worked on? I'm happy to help out if not. |
Contributor
|
@ifiokjr That would be great! I don't think the author is active on GitHub anymore (I just guess by looking at his contributions chart). |
Owner
|
Friendly bump :) |
Contributor
Author
|
Oh wow, I totally forgot. Thanks for the ping.
…Sent from my iPhone
On Mar 7, 2021, at 6:58 AM, Sindre Sorhus ***@***.***> wrote:
Friendly bump :)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
jonschlinkert
added a commit
to jonschlinkert/p-cancelable
that referenced
this pull request
Mar 9, 2021
onCancel handlers when a promise is canceled.onCancel handlers when a promise is canceled
Owner
|
Thanks :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15