Skip to content

Commit

Permalink
Throw error if onCancel is called after promise settlement (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored and sindresorhus committed Mar 31, 2019
1 parent 8746e2a commit c4ebb36
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class PCancelable {
};

const onCancel = handler => {
if (!this._isPending) {
throw new Error('The `onCancel` handler was attached after the promise settled.');
}

this._cancelHandlers.push(handler);
};

Expand Down

0 comments on commit c4ebb36

Please # to comment.