Created
November 1, 2014 21:13
-
-
Save rafkhan/d5c7ff95be115292f528 to your computer and use it in GitHub Desktop.
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
var Q = require('q'); | |
function getTheAnswerAsync() { | |
return Q.when(42); | |
} | |
function getTheQuestionAsync(answer) { | |
if (answer===42) { | |
return Q.when('What do you get if you multiply six by nine?'); | |
} else { | |
return Q.when('Don\'t panic!'); | |
} | |
} | |
process(function *() { | |
var theAnswer = yield getTheAnswerAsync(); | |
console.log('The answer:', theAnswer); | |
var theQuestion = yield getTheQuestionAsync(theAnswer); | |
console.log('The question:', theQuestion); | |
}); |
Bonus points if you can loop over n yield calls
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write the implementation of process() that would make this work, outputting:
Hint: this will only work on node ≥ 0.11 and you will need to use --harmony flag.