lib: defer pausing stdin to the next tick

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: https://github.com/nodejs/node/pull/19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2018-03-24 23:11:10 +01:00
parent baea5a893d
commit 5d70459606
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -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;
}