Skip to content

Instantly share code, notes, and snippets.

@julianlconnor
Created April 5, 2014 19:46
Show Gist options
  • Save julianlconnor/9997143 to your computer and use it in GitHub Desktop.
Save julianlconnor/9997143 to your computer and use it in GitHub Desktop.
q.all([only(), debug()])
.then(flatten)
.then(function(lines) {
var dfd = q.defer();
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(lines[0] + ' -- is this cool? (n)o , (y)es >', function(answer) {
if ( answer.toLower() === 'n' ) {
/**
* This should stop the promise chain and trigger the `fail`.
*/
dfd.reject('line has been rejected');
} else {
/**
* This should continue the promise chain;
*/
dfd.resolve('line has been accepted');
}
rl.close();
});
return dfd.promise;
})
.fail(function(err) {
console.log(err, '--- might not want these in yr commit ---\n');
exit(1);
})
.finally(function() {
console.log('status of dfd', dfd.promise.isFulfilled());
exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment