Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadStream paused and can't resume, when listened readable event #22032

Closed
a0000778 opened this issue Jul 30, 2018 · 2 comments
Closed

ReadStream paused and can't resume, when listened readable event #22032

a0000778 opened this issue Jul 30, 2018 · 2 comments

Comments

@a0000778
Copy link

a0000778 commented Jul 30, 2018

  • Version: 10.7.0
  • Platform: Darwin 17.7.0 / Linux 4.10.0
  • Subsystem: stream
const Readable=require('stream').Readable;

function testStream(){
	return new Readable({
		read(size){
			this.push(Buffer.alloc(size));
			this.push(null);
		}
	});
}
console.log('with readable:');
testStream()
	.on('readable',() => console.log('readable'))
	.on('data',buf => console.log(buf.length))
;

Output:

with readable:
readable

console.log('without readable:');
testStream()
	.on('data',buf => console.log(buf.length))
;

Output:

without readable:
16384
@lundibundi
Copy link
Member

That's by design.

If both 'readable' and 'data' are used at the same time, 'readable' takes precedence in controlling the flow, i.e. 'data' will be emitted only when stream.read() is called.

Readable doc

Therefore your stream will not be switched to 'flowing' state for you to receive all data in data event if the stream has at least one readable listener. This is somewhat recent change in #18994.

Also there is #21696 if it's accepted.

@a0000778
Copy link
Author

I missed this change, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants