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

stream: add isFlowing method #451

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/api/stream.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,24 @@ readable.resume()
readable.isPaused() // === false
```

#### readable.isFlowing()

* Return: `Boolean`

This method returns whether or not the `readable` is in flowing mode.

```javascript
var readable = new stream.Readable

readable.isFlowing() // === false
readable.resume()
readable.isFlowing() // === true
readable.pause()
readable.isFlowing() // === false
```



#### readable.pipe(destination[, options])

* `destination` {[Writable][] Stream} The destination for writing data
Expand Down
4 changes: 4 additions & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ Readable.prototype.isPaused = function() {
return this._readableState.flowing === false;
};

Readable.prototype.isFlowing = function() {
return this._readableState.flowing === true;
};

function readableAddChunk(stream, state, chunk, encoding, addToFront) {
var er = chunkInvalid(state, chunk);
if (er) {
Expand Down
2 changes: 1 addition & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ function flushStdio(subprocess) {
if (subprocess.stdio == null) return;
subprocess.stdio.forEach(function(stream, fd, stdio) {
if (!stream || !stream.readable || stream._consuming ||
stream._readableState.flowing)
stream.isFlowing())
return;
stream.resume();
});
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-stream-isflowing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var assert = require('assert');
var common = require('../common');

var stream = require('stream');

var readable = new stream.Readable;

readable._read = function(){};

assert.ok(!readable.isFlowing());

// make the stream start flowing...
readable.on('data', function(){});

assert.ok(readable.isFlowing());

readable.pause();
assert.ok(!readable.isFlowing());
readable.resume();
assert.ok(readable.isFlowing());