Created
June 2, 2016 19:53
-
-
Save anvk/99f5ade586d58fa6b59e10d9c89ae17f to your computer and use it in GitHub Desktop.
Sequential execution of Promises using generators and co()
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 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