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:
parent
baea5a893d
commit
5d70459606
@ -109,15 +109,22 @@ function setupStdio() {
|
|||||||
stdin._handle.readStop();
|
stdin._handle.readStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the user calls stdin.pause(), then we need to stop reading
|
// If the user calls stdin.pause(), then we need to stop reading
|
||||||
// immediately, so that the process can close down.
|
// once the stream implementation does so (one nextTick later),
|
||||||
|
// so that the process can close down.
|
||||||
stdin.on('pause', () => {
|
stdin.on('pause', () => {
|
||||||
|
process.nextTick(onpause);
|
||||||
|
});
|
||||||
|
|
||||||
|
function onpause() {
|
||||||
if (!stdin._handle)
|
if (!stdin._handle)
|
||||||
return;
|
return;
|
||||||
stdin._readableState.reading = false;
|
if (stdin._handle.reading && !stdin._readableState.flowing) {
|
||||||
stdin._handle.reading = false;
|
stdin._readableState.reading = false;
|
||||||
stdin._handle.readStop();
|
stdin._handle.reading = false;
|
||||||
});
|
stdin._handle.readStop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return stdin;
|
return stdin;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user