Skip to content

Commit 689e5c9

Browse files
committed
stream: return this from pause()/resume()
1 parent f91b047 commit 689e5c9

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

doc/api/stream.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ emission of a [`'data'` event][].
244244
#### readable.setEncoding(encoding)
245245

246246
* `encoding` {String} The encoding to use.
247+
* Return: `this`
247248

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

269270
#### readable.resume()
270271

272+
* Return: `this`
273+
271274
This method will cause the readable stream to resume emitting `data`
272275
events.
273276

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

287290
#### readable.pause()
288291

292+
* Return: `this`
293+
289294
This method will cause a stream in flowing mode to stop emitting
290295
`data` events, switching out of flowing mode. Any data that becomes
291296
available will remain in the internal buffer.

lib/_debugger.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,14 @@ function Interface(stdin, stdout, args) {
855855

856856

857857
Interface.prototype.pause = function() {
858-
if (this.killed || this.paused++ > 0) return false;
858+
if (this.killed || this.paused++ > 0) return this;
859859
this.repl.rli.pause();
860860
this.stdin.pause();
861+
return this;
861862
};
862863

863864
Interface.prototype.resume = function(silent) {
864-
if (this.killed || this.paused === 0 || --this.paused !== 0) return false;
865+
if (this.killed || this.paused === 0 || --this.paused !== 0) return this;
865866
this.repl.rli.resume();
866867
if (silent !== true) {
867868
this.repl.displayPrompt();
@@ -872,6 +873,7 @@ Interface.prototype.resume = function(silent) {
872873
this.waiting();
873874
this.waiting = null;
874875
}
876+
return this;
875877
};
876878

877879

lib/_stream_readable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ Readable.prototype.resume = function() {
705705
}
706706
resume(this, state);
707707
}
708+
return this;
708709
};
709710

710711
function resume(stream, state) {
@@ -731,6 +732,7 @@ Readable.prototype.pause = function() {
731732
this._readableState.flowing = false;
732733
this.emit('pause');
733734
}
735+
return this;
734736
};
735737

736738
function flow(stream) {

lib/readline.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ Interface.prototype.pause = function() {
268268
this.input.pause();
269269
this.paused = true;
270270
this.emit('pause');
271+
return this;
271272
};
272273

273274

@@ -276,6 +277,7 @@ Interface.prototype.resume = function() {
276277
this.input.resume();
277278
this.paused = false;
278279
this.emit('resume');
280+
return this;
279281
};
280282

281283

test/simple/test-stream2-basic.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,11 @@ test('adding readable triggers data flow', function(t) {
473473
t.end();
474474
});
475475
});
476+
477+
test('chainable', function(t) {
478+
var r = new R();
479+
r._read = function() {};
480+
var r2 = r.setEncoding('utf8').pause().resume().pause();
481+
t.equal(r, r2);
482+
t.end();
483+
});

0 commit comments

Comments
 (0)