1

The following code should write back everything the user puts in:

process.stdin.on('data', blob => {
    process.stdout.write(blob)
})

Indeed it does, but when I change on to once I expect the script to only write back one line and then exit:

process.stdin.once('data', blob => {
    process.stdout.write(blob)
})

However, it does not exit. Nothing ever happens again, no lines are written back, but the script keeps on running.

Looking at the documentation of once, I would expect it to exit since the documentation states:

The next time eventName is triggered, this listener is removed and then invoked.

Wouldn't that mean that the event loop queue becomes empty?


node process doesn't exit after firebase once seems relevant but the accepted answer now states:

Note that this is no longer applicable. Node.js will no longer hang when using once(), although it will be held open as long as there are active listeners subscribed to the remote server.

Which doesn't seem the case here.

Lieuwe Rooijakkers
  • 164
  • 1
  • 4
  • 14

0 Answers0