Last active
March 12, 2017 19:19
-
-
Save mightyguava/b255c236e1e22a0e90ebee8aff2661b6 to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - co() simple challenge
This file contains 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 deferred(val) { | |
return new Promise((resolve, reject) => resolve(val)); | |
} | |
co(function* asyncAdds() { | |
console.log(yield deferred(1)); // 1 | |
console.log(yield deferred(2)); // 2 | |
console.log(yield deferred(3)); // 3 | |
return 4; | |
}).then(function (result) { | |
console.log(result); // 4 | |
}); | |
function co(generator) { | |
return new Promise((resolve, reject) => { | |
// Your code goes here | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment