Skip to content

Instantly share code, notes, and snippets.

@grigio
Created February 19, 2014 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grigio/9101704 to your computer and use it in GitHub Desktop.
Save grigio/9101704 to your computer and use it in GitHub Desktop.
'use strict';
var thunk = require('thunkify');
var co = require('co');
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function sleep(ms, fn) {
setTimeout(function(){
fn(null, 'file: ');
}, ms);
}
function gets (text, fn) {
rl.question(text+" ", function(answer) {
fn(null, answer);
});
}
var sleep = thunk(sleep);
var gets = thunk(gets);
// The sequence!
co(function *(){
var name = yield gets('Your name?');
var age = yield gets('Your age?');
console.log('Good! ' + name +' - ' + age);
yield sleep(1000);
process.exit(0); // Because stdin remain open
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment