Skip to content

Instantly share code, notes, and snippets.

@rafkhan
Created November 1, 2014 21:13
Show Gist options
  • Save rafkhan/d5c7ff95be115292f528 to your computer and use it in GitHub Desktop.
Save rafkhan/d5c7ff95be115292f528 to your computer and use it in GitHub Desktop.
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);
});
@rafkhan
Copy link
Author

rafkhan commented Nov 1, 2014

Write the implementation of process() that would make this work, outputting:

The answer: 42
The question: What do you get if you multiply six by nine?

Hint: this will only work on node ≥ 0.11 and you will need to use --harmony flag.

@rafkhan
Copy link
Author

rafkhan commented Nov 1, 2014

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