streams2: pause() should be immediate
authorisaacs <i@izs.me>
Wed, 5 Dec 2012 01:34:17 +0000 (17:34 -0800)
committerisaacs <i@izs.me>
Fri, 14 Dec 2012 18:52:28 +0000 (10:52 -0800)
lib/_stream_readable.js
test/simple/test-fs-empty-readStream.js

index a0cb13c..6c4d95e 100644 (file)
@@ -521,15 +521,13 @@ 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) {
@@ -537,7 +535,7 @@ function emitDataEvents(stream) {
     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.
index a9b378f..d181c21 100644 (file)
@@ -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 () {
@@ -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 () {