Created
November 10, 2016 12:37
-
-
Save riston/dc93806208ff4aa85391aa4c15c9af38 to your computer and use it in GitHub Desktop.
Promise generator combination
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 bluebird = require("bluebird"); | |
const cop = bluebird.coroutine; | |
const exec = (time) => bluebird.delay(time).then(() => { | |
console.log("Time done", time); | |
return time; | |
}); | |
function* start() { | |
const promises = [ | |
bluebird.reject(), | |
exec(100), | |
exec(1000), | |
exec(20), | |
exec(120), | |
bluebird.reject(), | |
]; | |
try { | |
yield Promise.all(promises); | |
console.log("Only if all promises are resolved"); | |
} catch (e) { | |
console.log("Error captured", e); | |
} | |
console.log("Continue code here"); | |
return 0; | |
} | |
cop(start)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment