Skip to content

Commit 6777a82

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
1 parent 3b12a8d commit 6777a82

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

doc/api/stream.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,28 @@ 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); pass.unpipe(writable); // flowing is now false
616+
pass.on('data', (chunk) => { console.log(chunk.toString()); });
617+
pass.write('ok'); // will not emit 'data'
618+
pass.resume(); // must be called to make 'data' being emitted
619+
```
609620

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

0 commit comments

Comments
 (0)