Last active
November 20, 2020 13:45
-
-
Save jxm262/342dcc03f9cb8aa22722 to your computer and use it in GitHub Desktop.
Bluebird - chained promises cancel() example
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
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'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, do you know how can I do to cancel a Promise.each() ?