Skip to content

Commit

Permalink
lib: defer pausing stdin to the next tick
Browse files Browse the repository at this point in the history
This is done to match the stream implementation, which also
only actually stops reading in the next tick after the `'pause'`
event is emitted.

PR-URL: #19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed May 14, 2018
1 parent 9e1dcdc commit 61415dc
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/internal/process/stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,22 @@ function setupStdio() {
stdin._handle.readStop();
}

// if the user calls stdin.pause(), then we need to stop reading
// immediately, so that the process can close down.
// If the user calls stdin.pause(), then we need to stop reading
// once the stream implementation does so (one nextTick later),
// so that the process can close down.
stdin.on('pause', () => {
process.nextTick(onpause);
});

function onpause() {
if (!stdin._handle)
return;
stdin._readableState.reading = false;
stdin._handle.reading = false;
stdin._handle.readStop();
});
if (stdin._handle.reading && !stdin._readableState.flowing) {
stdin._readableState.reading = false;
stdin._handle.reading = false;
stdin._handle.readStop();
}
}

return stdin;
}
Expand Down

0 comments on commit 61415dc

Please sign in to comment.