Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
streams2: pause() should be immediate
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 6, 2012
1 parent 757e26b commit 2615d73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 3 additions & 5 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,23 +521,21 @@ Readable.prototype.addListener = Readable.prototype.on;
// If the user uses them, then switch into old mode.
Readable.prototype.resume = function() {
emitDataEvents(this);
return this.resume();
};

Readable.prototype.pause = function() {
emitDataEvents(this);
return this.pause();
emitDataEvents(this, true);
};

function emitDataEvents(stream) {
function emitDataEvents(stream, startPaused) {
var state = stream._readableState;

if (state.flowing) {
// https://github.com/isaacs/readable-stream/issues/16
throw new Error('Cannot switch to old mode now.');
}

var paused = false;
var paused = startPaused || false;
var readable = false;

// convert to an old-style stream.
Expand Down
6 changes: 4 additions & 2 deletions test/simple/test-fs-empty-readStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ fs.open(emptyFile, 'r', function (error, fd) {
var read = fs.createReadStream(emptyFile, { 'fd': fd });

read.once('data', function () {
throw new Error("data event should not emit");
throw new Error('data event should not emit');
});

var readEmit = false;
read.once('end', function () {
readEmit = true;
console.error('end event 1');
});

setTimeout(function () {
Expand All @@ -52,12 +53,13 @@ fs.open(emptyFile, 'r', function (error, fd) {
read.pause();

read.once('data', function () {
throw new Error("data event should not emit");
throw new Error('data event should not emit');
});

var readEmit = false;
read.once('end', function () {
readEmit = true;
console.error('end event 2');
});

setTimeout(function () {
Expand Down

0 comments on commit 2615d73

Please sign in to comment.