You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a 'readable' event handler automatically makes the stream stop flowing, and the data has to be consumed via readable.read(). If the 'readable' event handler is removed, then the stream will start flowing again if there is a 'data' event handler.
I added both the readable and data event listener, then I found both of them emit.
const{ Readable }=require('stream');classMyReadableextendsReadable{_read(){console.log('_read has been called');}}constreader=newMyReadable();constinitSize=6;for(leti=0;i<initSize;i++){reader.push(Buffer.from([i&0xff]));}reader.on('readable',function(){console.log('get data',reader.read());});reader.on('data',(chunk)=>{console.log('stream mod2',reader.readableFlowing);console.log('data event',chunk);});console.log('stream mode',reader.readableFlowing);
The output of code is:
stream mode false
_read has been called
stream mode2 false
data event <Buffer 00 01 02 03 04 05>
get data <Buffer 00 01 02 03 04 05>
It seemed that the buffer can been read in flowing mode and paused mode at same time.
The text was updated successfully, but these errors were encountered:
Affected URL(s)
https://nodejs.org/docs/latest/api/stream.html#two-reading-modes
Description of the problem
As the docs said:
I added both the readable and data event listener, then I found both of them emit.
The output of code is:
It seemed that the buffer can been read in flowing mode and paused mode at same time.
The text was updated successfully, but these errors were encountered: