Skip to content

Commit

Permalink
stream: readable.off
Browse files Browse the repository at this point in the history
We have special logic in removeListener() which must apply
to off() as well.
  • Loading branch information
ronag committed Sep 8, 2019
1 parent 17d87d5 commit 9768c24
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ Readable.prototype.removeListener = function(ev, fn) {

return res;
};
Readable.prototype.off = Readable.prototype.removeListener;

Readable.prototype.removeAllListeners = function(ev) {
const res = Stream.prototype.removeAllListeners.apply(this, arguments);
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-stream-readable-readable-then-resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const common = require('../common');
const { Readable } = require('stream');
const assert = require('assert');

// This test verifies that a stream could be resumed after
// removing the readable event in the same tick
Expand All @@ -24,6 +25,7 @@ function check(s) {
const readableListener = common.mustNotCall();
s.on('readable', readableListener);
s.on('end', common.mustCall());
assert.strictEqual(s.removeListener, s.off);
s.removeListener('readable', readableListener);
s.resume();
}

0 comments on commit 9768c24

Please sign in to comment.