Created
February 19, 2014 21:12
-
-
Save grigio/9101704 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
'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