Skip to content

Commit

Permalink
fix(cancel): fix cancel handling
Browse files Browse the repository at this point in the history
  • Loading branch information
suguru03 committed Oct 22, 2017
1 parent 3043af2 commit 104a927
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 450 deletions.
13 changes: 10 additions & 3 deletions lib/aigle.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Aigle extends AigleCore {
* });
*/
cancel() {
if (this._execute === execute) {
if (this._execute === execute || this._resolved !== 0) {
return;
}
const { _onCancelQueue } = this;
Expand All @@ -169,7 +169,11 @@ class Aigle extends AigleCore {
array[i]();
}
}
this._reject(new CancellationError('late cancellation observer'));
this._resolved = 2;
this._value = new CancellationError('late cancellation observer');
if (this._parent) {
this._parent.cancel();
}
}

suppressUnhandledRejections() {
Expand Down Expand Up @@ -3639,6 +3643,9 @@ function executeWithCancel(executor) {
if (executor === undefined) {
return;
}
if (value instanceof Aigle && value._resolved === 0) {
this._parent = value;
}
executor = undefined;
callReceiver(this, value);
}, reason => {
Expand All @@ -3651,7 +3658,7 @@ function executeWithCancel(executor) {
if (typeof handler !== 'function') {
throw new TypeError('onCancel must be function');
}
if (executor === undefined) {
if (this._resolved !== 0) {
return;
}
if (this._onCancelQueue === undefined) {
Expand Down
Loading

0 comments on commit 104a927

Please sign in to comment.