-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: correctly pause and resume after once('readable')
Fixes: #24281 PR-URL: #24366 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
- Loading branch information
1 parent
f0602f8
commit fa60eb8
Showing
2 changed files
with
41 additions
and
3 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
29 changes: 29 additions & 0 deletions
29
test/parallel/test-stream-readable-readable-then-resume.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,29 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { Readable } = require('stream'); | ||
|
||
// This test verifies that a stream could be resumed after | ||
// removing the readable event in the same tick | ||
|
||
check(new Readable({ | ||
objectMode: true, | ||
highWaterMark: 1, | ||
read() { | ||
if (!this.first) { | ||
this.push('hello'); | ||
this.first = true; | ||
return; | ||
} | ||
|
||
this.push(null); | ||
} | ||
})); | ||
|
||
function check(s) { | ||
const readableListener = common.mustNotCall(); | ||
s.on('readable', readableListener); | ||
s.on('end', common.mustCall()); | ||
s.removeListener('readable', readableListener); | ||
s.resume(); | ||
} |