-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously we would just resume "flowing" the stream without reseting the "paused" state. Fixes this by properly using pause/resume methods for .pipe. Fixes: #41785
- Loading branch information
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { PassThrough } = require('stream'); | ||
|
||
// THIRD EXPERIMENT | ||
console.info('\n********** THIRD EXPERIMENT **********'); | ||
const source3 = new PassThrough(); | ||
const target3 = new PassThrough(); | ||
|
||
// stall target3 | ||
const chunk = Buffer.allocUnsafe(1000); | ||
let chunks = 1; | ||
while (target3.write(chunk)) chunks++; | ||
console.info(`${chunks} chunks of ${chunk.length} bytes to stall target3`); | ||
|
||
// `Readable.pipe()` PAUSES the source if the target needs drain (only in | ||
// version >= v14.17.0) and it does not resume it after drain | ||
console.info(`source3 before pipe. Paused: ${source3.isPaused()}`); | ||
source3.pipe(target3); | ||
console.info(`source3 after pipe. Paused: ${source3.isPaused()}`); | ||
target3.on('drain', () => { | ||
console.info('target3 drained'); | ||
console.info(`source3 after drain. Paused: ${source3.isPaused()}`); | ||
console.info(source3.readableFlowing); | ||
}); | ||
target3.on('data', () => {}); |