Skip to content

Commit

Permalink
stream: return this from pause()/resume()
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Sep 4, 2013
1 parent f91b047 commit 689e5c9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/api/stream.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ emission of a [`'data'` event][].
#### readable.setEncoding(encoding)

* `encoding` {String} The encoding to use.
* Return: `this`

Call this function to cause the stream to return strings of the
specified encoding instead of Buffer objects. For example, if you do
Expand All @@ -268,6 +269,8 @@ readable.on('data', function(chunk) {

#### readable.resume()

* Return: `this`

This method will cause the readable stream to resume emitting `data`
events.

Expand All @@ -286,6 +289,8 @@ readable.on('end', function(chunk) {

#### readable.pause()

* Return: `this`

This method will cause a stream in flowing mode to stop emitting
`data` events, switching out of flowing mode. Any data that becomes
available will remain in the internal buffer.
Expand Down
6 changes: 4 additions & 2 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,13 +855,14 @@ function Interface(stdin, stdout, args) {


Interface.prototype.pause = function() {
if (this.killed || this.paused++ > 0) return false;
if (this.killed || this.paused++ > 0) return this;
this.repl.rli.pause();
this.stdin.pause();
return this;
};

Interface.prototype.resume = function(silent) {
if (this.killed || this.paused === 0 || --this.paused !== 0) return false;
if (this.killed || this.paused === 0 || --this.paused !== 0) return this;
this.repl.rli.resume();
if (silent !== true) {
this.repl.displayPrompt();
Expand All @@ -872,6 +873,7 @@ Interface.prototype.resume = function(silent) {
this.waiting();
this.waiting = null;
}
return this;
};


Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ Readable.prototype.resume = function() {
}
resume(this, state);
}
return this;
};

function resume(stream, state) {
Expand All @@ -731,6 +732,7 @@ Readable.prototype.pause = function() {
this._readableState.flowing = false;
this.emit('pause');
}
return this;
};

function flow(stream) {
Expand Down
2 changes: 2 additions & 0 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Interface.prototype.pause = function() {
this.input.pause();
this.paused = true;
this.emit('pause');
return this;
};


Expand All @@ -276,6 +277,7 @@ Interface.prototype.resume = function() {
this.input.resume();
this.paused = false;
this.emit('resume');
return this;
};


Expand Down
8 changes: 8 additions & 0 deletions test/simple/test-stream2-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,11 @@ test('adding readable triggers data flow', function(t) {
t.end();
});
});

test('chainable', function(t) {
var r = new R();
r._read = function() {};
var r2 = r.setEncoding('utf8').pause().resume().pause();
t.equal(r, r2);
t.end();
});

0 comments on commit 689e5c9

Please sign in to comment.