Skip to content

Commit 0b432e0

Browse files
committed
doc: resume a stream after pipe() and unpipe()
Clarifies the behavior of streams when _readableState.flowing is false. resume() must be called explicitly for the 'data' event to be emitted again. Fixes: #1041 PR-URL: #13329 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 7637347 commit 0b432e0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

doc/api/stream.md

+18-4
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,31 @@ possible states:
595595
* `readable._readableState.flowing = true`
596596

597597
When `readable._readableState.flowing` is `null`, no mechanism for consuming the
598-
streams data is provided so the stream will not generate its data.
599-
600-
Attaching a listener for the `'data'` event, calling the `readable.pipe()`
598+
streams data is provided so the stream will not generate its data. While in this
599+
state, attaching a listener for the `'data'` event, calling the `readable.pipe()`
601600
method, or calling the `readable.resume()` method will switch
602601
`readable._readableState.flowing` to `true`, causing the Readable to begin
603602
actively emitting events as data is generated.
604603

605604
Calling `readable.pause()`, `readable.unpipe()`, or receiving "back pressure"
606605
will cause the `readable._readableState.flowing` to be set as `false`,
607606
temporarily halting the flowing of events but *not* halting the generation of
608-
data.
607+
data. While in this state, attaching a listener for the `'data'` event
608+
would not cause `readable._readableState.flowing` to switch to `true`.
609+
610+
```js
611+
const { PassThrough, Writable } = require('stream');
612+
const pass = new PassThrough();
613+
const writable = new Writable();
614+
615+
pass.pipe(writable);
616+
pass.unpipe(writable);
617+
// flowing is now false
618+
619+
pass.on('data', (chunk) => { console.log(chunk.toString()); });
620+
pass.write('ok'); // will not emit 'data'
621+
pass.resume(); // must be called to make 'data' being emitted
622+
```
609623

610624
While `readable._readableState.flowing` is `false`, data may be accumulating
611625
within the streams internal buffer.

0 commit comments

Comments
 (0)