Skip to content

Instantly share code, notes, and snippets.

@gunar
Last active February 1, 2016 11:26
Show Gist options
  • Save gunar/09a8596cf958c4fbe1ad to your computer and use it in GitHub Desktop.
Save gunar/09a8596cf958c4fbe1ad to your computer and use it in GitHub Desktop.
Promise cancelation
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