Last active
February 1, 2016 11:26
-
-
Save gunar/09a8596cf958c4fbe1ad to your computer and use it in GitHub Desktop.
Promise cancelation
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
const myPromise = new Promise((resolve, reject) => { | |
setTimeout(resolve, 1000, 42); | |
}); | |
var cancel; | |
const myCancelator = new Promise((resolve, reject) => { | |
cancel = reject; | |
}); | |
Promise.race([ | |
myPromise, | |
myCancelator, | |
]).then(console.log, console.error); | |
cancel('Whoops!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment