Skip to content

Instantly share code, notes, and snippets.

@Fishrock123
Last active August 29, 2015 14:01
Show Gist options
  • Save Fishrock123/abdafd59f22ad3e71589 to your computer and use it in GitHub Desktop.
Save Fishrock123/abdafd59f22ad3e71589 to your computer and use it in GitHub Desktop.
not thunkifying correctly or something (fixed)
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