Skip to content

Instantly share code, notes, and snippets.

@riston
Created November 10, 2016 12:37
Show Gist options
  • Save riston/dc93806208ff4aa85391aa4c15c9af38 to your computer and use it in GitHub Desktop.
Save riston/dc93806208ff4aa85391aa4c15c9af38 to your computer and use it in GitHub Desktop.
Promise generator combination
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