Last active
January 29, 2018 01:08
-
-
Save kitak/1fded98909740458220cab963bba1b7e to your computer and use it in GitHub Desktop.
question promisify
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
const readline = require('readline') | |
const util = require('util') | |
const rl = readline.createInterface({input: process.stdin, output: process.stdout}) | |
rl.question[util.promisify.custom] = (arg) => { | |
return new Promise((resolve) => { | |
rl.question(arg, resolve); | |
}); | |
}; | |
const questionPromise = util.promisify(rl.question); | |
questionPromise('What do you think of Node.js? ').then((answer) => { | |
console.log(answer); | |
rl.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment