Last active
August 29, 2015 14:23
-
-
Save amitu/6de606aa5671add11978 to your computer and use it in GitHub Desktop.
node, Q and generators
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
// $ npm install q | |
// $ node --harmony tyield.js | |
var Q = require("q"); | |
function timeoutPromose(delay) { | |
var d = Q.defer(); | |
setTimeout(function(){ | |
d.resolve("done"); | |
}, delay); | |
return d.promise; | |
} | |
function *timed() { | |
console.log("going to sleep for 1"); | |
yield timeoutPromose(1000); | |
console.log("now we are talking") | |
yield timeoutPromose(2000); | |
console.log("done"); | |
} | |
Q.async(timed)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment