streams2: Emit pause/resume events

This commit is contained in:
isaacs 2012-12-12 22:17:57 -08:00
Родитель 8fe7b0c910
Коммит 04541cf7bc
1 изменённых файлов: 4 добавлений и 0 удалений

Просмотреть файл

@ -524,10 +524,12 @@ Readable.prototype.addListener = Readable.prototype.on;
Readable.prototype.resume = function() { Readable.prototype.resume = function() {
emitDataEvents(this); emitDataEvents(this);
this.read(0); this.read(0);
this.emit('resume');
}; };
Readable.prototype.pause = function() { Readable.prototype.pause = function() {
emitDataEvents(this, true); emitDataEvents(this, true);
this.emit('pause');
}; };
function emitDataEvents(stream, startPaused) { function emitDataEvents(stream, startPaused) {
@ -561,6 +563,7 @@ function emitDataEvents(stream, startPaused) {
stream.pause = function() { stream.pause = function() {
paused = true; paused = true;
this.emit('pause');
}; };
stream.resume = function() { stream.resume = function() {
@ -571,6 +574,7 @@ function emitDataEvents(stream, startPaused) {
}); });
else else
this.read(0); this.read(0);
this.emit('resume');
}; };
// now make it start, just in case it hadn't already. // now make it start, just in case it hadn't already.