Skip to content

Instantly share code, notes, and snippets.

@anvk
Created June 2, 2016 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anvk/99f5ade586d58fa6b59e10d9c89ae17f to your computer and use it in GitHub Desktop.
Save anvk/99f5ade586d58fa6b59e10d9c89ae17f to your computer and use it in GitHub Desktop.
Sequential execution of Promises using generators and co()
function asyncFunc(e) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(e), e * 1000);
});
}
const arr = [1, 2, 3];
co(function* () {
let result = [];
return arr.map(element => {
return yield asyncFunc(element);
})
}).catch(error => console.error(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment