tj / co-prompt

sane terminal user-input for node.js using thunks / generators
192 stars 23 forks source link

My Node.js process doesn't terminate when using prompt function #9

Open davideicardi opened 8 years ago

davideicardi commented 8 years ago

I suspect that the problem is that process.stdin is still referenced. See this SO answer.

I have tried another approach using readline:

const readline = require('readline');

function prompt(msg){
  return new Promise((resolve, reject) => {
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });

    rl.question(msg, (answer) => {
      rl.close();
      resolve(answer);
    });
  });
}

What do you think?

eladnava commented 8 years ago

You need to explicitly pause stdin after using co-prompt with the following code, at the end of your execution flow:

// Gotta pause stdin after we're done so it doesn't look like the process is stuck
process.stdin.pause();
afoeder commented 4 years ago

should this be added to the documentation? The need to add a process.stdin.pause();?