heapwolf / prompt-sync

a synchronous prompt for node.js
MIT License
211 stars 42 forks source link

unexitable when run in loop #28

Closed maxp-edcast closed 6 years ago

maxp-edcast commented 6 years ago

I have the following simple coffeescript file:

# test.coffee
ps = require("prompt-sync")()
out = NaN
while isNaN out
  out = parseInt ps("enter input")

When I run this using coffee test.coffee and instead of entering text try exiting with control+c, it does not exit but just goes to the next tick of the while loop. When I enter "1", it exits as expected.

There's also the same behavior in Javascript. Here is the same script compiled to JS:

// test.js
// Generated by CoffeeScript 2.0.3
(function() {
  var out, ps;

  ps = require("prompt-sync")();

  out = 0/0;

  while (isNaN(out)) {
    out = parseInt(ps("enter input"));
  }

}).call(this);

When running this with node test.js, the same behavior occurs.

Is this expected, or should we be manually handling control+c?

maxp-edcast commented 6 years ago

Sorry, I didnt read the readme ... the note on sigint is there. I wonder if sigint should default to true, I don't see the benefit in having false be the default, and it made me have to kill -9 the process.