Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demystifying Async Programming in Javascript - co() simple solution
function co(generator) {
return new Promise((resolve, reject) => {
const g = generator();
function next(nextVal) {
const ret = g.next(nextVal);
if (ret.done) {
return resolve(ret.value);
}
ret.value.then(next);
}
next();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.