Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,10 @@ function on(emitter, event, options = kEmptyObject) {
},

return() {
if (paused && !finished) {
paused = false;
emitter.resume();
}
return closeHandler();
},

Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-events-on-async-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const common = require('../common');
const assert = require('assert');
const { on, EventEmitter } = require('events');
const { PassThrough } = require('stream');
const {
NodeEventTarget,
kEvents
Expand Down Expand Up @@ -123,6 +124,16 @@ async function throwInLoop() {
assert.strictEqual(ee.listenerCount('error'), 0);
}

async function returnResumesPausedEmitter() {
const stream = new PassThrough();
const iterable = on(stream, 'data', { highWaterMark: 1 });
stream.write('a');
stream.write('b');
assert.strictEqual(stream.isPaused(), true);
await iterable.return();
assert.strictEqual(stream.isPaused(), false);
}

async function next() {
const ee = new EventEmitter();
const iterable = on(ee, 'foo');
Expand Down Expand Up @@ -411,6 +422,7 @@ async function run() {
errorDelayed,
throwInLoop,
next,
returnResumesPausedEmitter,
nextError,
iterableThrow,
eventTarget,
Expand Down
Loading