Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Not documented: stream.readable() is fired once when read is impossible #14597

Closed
socketpair opened this issue Apr 10, 2015 · 4 comments
Closed

Comments

@socketpair
Copy link

Not documented: stream.readable() is fired once when read is impossible. I think, that just before 'end' event.

Current documentation says: When a chunk of data can be read from the stream. But in that case, chunk CAN_NOT be read (stream.read() will return null).

@socketpair socketpair changed the title Not documented: stream.readable() is fired when read is impossible Not documented: stream.readable() is fired once when read is impossible Apr 10, 2015
@jasnell
Copy link
Member

jasnell commented Jun 25, 2015

It's a bit confusing but it's not a bug. readable tells you that data can be read, it does not tell you if there is actually data that will be read. Your code has to be prepared to get a null back when calling read. The example https://nodejs.org/api/stream.html#stream_readable_read_size illustrates such handling.

@jasnell jasnell closed this as completed Jun 25, 2015
@socketpair
Copy link
Author

Please reopen. I understand that this is not a bug, but as I think, this non-trivial thing should be documented. For example, is it guaranteed that readable will be fired BEFORE end ? moreover, is it guaranteed that readable will fire if connection aborted on remote side?

@jasnell
Copy link
Member

jasnell commented Jun 26, 2015

OK. Care to help out with a PR? :)

@jasnell jasnell reopened this Jun 26, 2015
jasnell added a commit to jasnell/node-joyent that referenced this issue Jul 6, 2015
per nodejs#14597

Indicate that `'readable'` indicates only that data can
be read from the stream, not that there is actually data
to be consumed. `readable.read([size])` can still return
null. Includes an example that illustrates the point.
@jasnell
Copy link
Member

jasnell commented Jul 6, 2015

I've got a PR open to clarify this. Will land shortly once reviewed.

@jasnell jasnell closed this as completed Jul 6, 2015
jasnell added a commit to jasnell/node-joyent that referenced this issue Jul 6, 2015
per nodejs#14597

Indicate that `'readable'` indicates only that data can
be read from the stream, not that there is actually data
to be consumed. `readable.read([size])` can still return
null. Includes an example that illustrates the point.
jasnell added a commit that referenced this issue Jul 10, 2015
per #14597

Indicate that `'readable'` indicates only that data can
be read from the stream, not that there is actually data
to be consumed. `readable.read([size])` can still return
null. Includes an example that illustrates the point.

Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #25635
jasnell added a commit to jasnell/node-joyent that referenced this issue Jul 10, 2015
per nodejs#14597

Indicate that `'readable'` indicates only that data can
be read from the stream, not that there is actually data
to be consumed. `readable.read([size])` can still return
null. Includes an example that illustrates the point.

Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#25635
jasnell added a commit that referenced this issue Aug 4, 2015
per #14597

Indicate that `'readable'` indicates only that data can
be read from the stream, not that there is actually data
to be consumed. `readable.read([size])` can still return
null. Includes an example that illustrates the point.

Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #25591
jasnell added a commit to jasnell/node that referenced this issue Aug 4, 2015
per nodejs/node-v0.x-archive#14597

Indicate that `'readable'` indicates only that data can
be read from the stream, not that there is actually data
to be consumed. `readable.read([size])` can still return
null. Includes an example that illustrates the point.

Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs/node-v0.x-archive#25591
jBarz pushed a commit to ibmruntimes/node that referenced this issue Nov 4, 2016
per nodejs#14597

Indicate that `'readable'` indicates only that data can
be read from the stream, not that there is actually data
to be consumed. `readable.read([size])` can still return
null. Includes an example that illustrates the point.

Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#25591
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants