-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: flow for 'data' listeners upon 'readable' remove
When there is at least one 'data' listener try to flow when last 'readable' listener gets removed and the stream is not piped. Currently if we have both 'readable' and 'data' listeners set only 'readable' listener will get called and stream will be stalled without 'data' and 'end' events if 'readable' listener neither read()'s nor resume()'s the stream. Fixes: #21398
- Loading branch information
1 parent
566d11a
commit 6fa9528
Showing
3 changed files
with
71 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,29 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
// This test ensures that if we have both 'readable' and 'data' | ||
// listeners on Readable instance once the 'readable' listeners | ||
// are gone and there are still 'data' listeners stream will try | ||
// to flow to satisfy the 'data' listeners. | ||
|
||
const assert = require('assert'); | ||
const { Readable } = require('stream'); | ||
|
||
const r = new Readable({ | ||
read: () => {}, | ||
}); | ||
|
||
const data = ['foo', 'bar', 'baz']; | ||
|
||
let receivedData = ''; | ||
r.once('readable', common.mustCall()); | ||
r.on('data', (chunk) => receivedData += chunk); | ||
r.once('end', common.mustCall(() => { | ||
assert.strictEqual(receivedData, data.join('')); | ||
})); | ||
|
||
r.push(data[0]); | ||
r.push(data[1]); | ||
r.push(data[2]); | ||
r.push(null); |