Last active
March 9, 2016 14:08
-
-
Save inceax/b40ad9c270d341d1b666 to your computer and use it in GitHub Desktop.
node.js co example
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
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