Last active
August 29, 2015 14:01
-
-
Save Fishrock123/abdafd59f22ad3e71589 to your computer and use it in GitHub Desktop.
not thunkifying correctly or something (fixed)
This file contains hidden or 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 co = require('co') | |
var readln = require('readline') | |
var rl = readln.createInterface({ | |
input: process.stdin | |
, output: process.stdout | |
}) | |
// make rl.question a thunk | |
function confirm(question) { | |
return function(done) { | |
var called = false | |
rl.question.call(rl, question, function(result) { | |
if (called) return | |
called = true | |
done.call(null, undefined, result) | |
}) | |
} | |
} | |
co(thing())(function (err) { | |
if (err) throw err | |
process.exit() | |
}) | |
function* thing() { | |
var result = yield confirm('Continue? (yes) ') | |
if ('string' == typeof result && /n|no/i.test(result)) process.exit() | |
console.log('continued') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment