Skip to content

Instantly share code, notes, and snippets.

@danielecr
Created May 11, 2022 08:07
Show Gist options
  • Save danielecr/fd1f0d9ac5667c38bc1851fc552bbfb6 to your computer and use it in GitHub Desktop.
Save danielecr/fd1f0d9ac5667c38bc1851fc552bbfb6 to your computer and use it in GitHub Desktop.
await for the prompt question
const readline = require('readline');
const waitPrompt = (line) => new Promise((resolve,reject) => {
const handle = (msg) => (err) => {
//console.log(msg, err);
reject(err);
}
const d = require('domain').create();
d.on('error', handle("ERROR"));
d.run(() => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(line, function (name) {
resolve(name);
rl.close();
});
rl.on('error', reject);
})
});
module.exports = waitPrompt
/*
waitPrompt('ciao?').then(risposta=> {
console.log("reply", risposta);
});
// or use await:
let resp = await waitPrompt('Is it Monday? ');
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment