Skip to content

Instantly share code, notes, and snippets.

@inceax
Last active March 9, 2016 14:08
Show Gist options
  • Save inceax/b40ad9c270d341d1b666 to your computer and use it in GitHub Desktop.
Save inceax/b40ad9c270d341d1b666 to your computer and use it in GitHub Desktop.
node.js co example
co(function* () {
var a = yield new Promise(function(resolve, reject) {
setTimeout(() => resolve("ok"), 100);
});
console.log("result: " + a);
var b = yield new Promise(function(resolve, reject) {
setTimeout(() => reject("fail"), 100);
});
console.log("result: " + b);
}).catch(function(e) {
console.log("error: " + e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment