-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: do not emit readable if the stream ended
Fixes a regression introduced by the once-per-microtick 'readable' event emission. See: #17979 PR-URL: #18372 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
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
39 changes: 39 additions & 0 deletions
39
test/parallel/test-stream-readable-no-unneeded-readable.js
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,39 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const { Readable, PassThrough } = require('stream'); | ||
|
||
const source = new Readable({ | ||
read: () => {} | ||
}); | ||
|
||
source.push('foo'); | ||
source.push('bar'); | ||
source.push(null); | ||
|
||
const pt = source.pipe(new PassThrough()); | ||
|
||
const wrapper = new Readable({ | ||
read: () => { | ||
let data = pt.read(); | ||
|
||
if (data) { | ||
wrapper.push(data); | ||
return; | ||
} | ||
|
||
pt.once('readable', function() { | ||
data = pt.read(); | ||
if (data) { | ||
wrapper.push(data); | ||
} | ||
// else the end event should fire | ||
}); | ||
} | ||
}); | ||
|
||
pt.once('end', function() { | ||
wrapper.push(null); | ||
}); | ||
|
||
wrapper.resume(); | ||
wrapper.once('end', common.mustCall()); |