Skip to content

Commit 61415dc

Browse files
committed
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: #19377 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9e1dcdc commit 61415dc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/internal/process/stdio.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,22 @@ function setupStdio() {
109109
stdin._handle.readStop();
110110
}
111111

112-
// if the user calls stdin.pause(), then we need to stop reading
113-
// immediately, so that the process can close down.
112+
// If the user calls stdin.pause(), then we need to stop reading
113+
// once the stream implementation does so (one nextTick later),
114+
// so that the process can close down.
114115
stdin.on('pause', () => {
116+
process.nextTick(onpause);
117+
});
118+
119+
function onpause() {
115120
if (!stdin._handle)
116121
return;
117-
stdin._readableState.reading = false;
118-
stdin._handle.reading = false;
119-
stdin._handle.readStop();
120-
});
122+
if (stdin._handle.reading && !stdin._readableState.flowing) {
123+
stdin._readableState.reading = false;
124+
stdin._handle.reading = false;
125+
stdin._handle.readStop();
126+
}
127+
}
121128

122129
return stdin;
123130
}

0 commit comments

Comments
 (0)