Skip to content

Commit 044e753

Browse files
mcollinaBethGriggs
authored andcommitted
stream: make _read() be called indefinitely if the user wants so
Fixes: #26097 PR-URL: #26135 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 76af23a commit 044e753

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

‎lib/_stream_readable.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ Readable.prototype.read = function(n){
494494
};
495495

496496
functiononEofChunk(stream,state){
497+
debug('onEofChunk');
497498
if(state.ended)return;
498499
if(state.decoder){
499500
varchunk=state.decoder.end();
@@ -524,6 +525,7 @@ function onEofChunk(stream, state){
524525
// a nextTick recursion warning, but that's not so bad.
525526
functionemitReadable(stream){
526527
varstate=stream._readableState;
528+
debug('emitReadable',state.needReadable,state.emittedReadable);
527529
state.needReadable=false;
528530
if(!state.emittedReadable){
529531
debug('emitReadable',state.flowing);
@@ -537,6 +539,7 @@ function emitReadable_(stream){
537539
debug('emitReadable_',state.destroyed,state.length,state.ended);
538540
if(!state.destroyed&&(state.length||state.ended)){
539541
stream.emit('readable');
542+
state.emittedReadable=false;
540543
}
541544

542545
// The stream needs another readable event if
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
const{ Readable }=require('stream');
6+
7+
constbuf=Buffer.alloc(8192);
8+
9+
constreadable=newReadable({
10+
read: common.mustCall(function(){
11+
this.push(buf);
12+
},31)
13+
});
14+
15+
leti=0;
16+
17+
readable.on('readable',common.mustCall(function(){
18+
if(i++===10){
19+
// We will just terminate now.
20+
process.removeAllListeners('readable');
21+
return;
22+
}
23+
24+
constdata=readable.read();
25+
// TODO(mcollina): there is something odd in the highWaterMark logic
26+
// investigate.
27+
if(i===1){
28+
assert.strictEqual(data.length,8192*2);
29+
}else{
30+
assert.strictEqual(data.length,8192*3);
31+
}
32+
},11));

0 commit comments

Comments
(0)