Skip to content

Instantly share code, notes, and snippets.

@jxm262
Last active November 20, 2020 13:45
Show Gist options
  • Save jxm262/342dcc03f9cb8aa22722 to your computer and use it in GitHub Desktop.
Save jxm262/342dcc03f9cb8aa22722 to your computer and use it in GitHub Desktop.
Bluebird - chained promises cancel() example
function a (obj) {
return new Promise(function (res, rej) {
res(obj);
});
};
function chainingClosure(start){
console.log('starting regular bluebird promise example...');
var p = a(start)
.then(function(val){
console.log(val);
return (start === 'without cancel() call') ? a('run next then') : p.cancel();
})
.then(function(val){
console.log(val);
console.log('--------------');
})
.cancellable()
.catch(Promise.CancellationError, function () {
console.log('was cancelled');
return;
});
return p;
};
Promise.resolve()
.then(function(){
return chainingClosure('without cancel() call');
})
.then(function(){
return chainingClosure('run with cancel');
});
@matispf84
Copy link

Hi, do you know how can I do to cancel a Promise.each() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment