Skip to content

Commit 5ce3b6d

Browse files
mcollinatargos
authored andcommitted
stream: ended streams should resolve the async iteration
Fixes: #23891 PR-URL: #23901 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2cc4f5c commit 5ce3b6d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/internal/streams/async_iterator.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ const createReadableStreamAsyncIterator = (stream) => {
127127
[kLastResolve]: { value: null, writable: true },
128128
[kLastReject]: { value: null, writable: true },
129129
[kError]: { value: null, writable: true },
130-
[kEnded]: { value: false, writable: true },
130+
[kEnded]: {
131+
value: stream._readableState.endEmitted,
132+
writable: true
133+
},
131134
[kLastPromise]: { value: null, writable: true },
132135
// the function passed to new Promise
133136
// is cached so we avoid allocating a new

test/parallel/test-stream-readable-async-iterators.js

+18
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,24 @@ async function tests() {
362362
assert.strictEqual(e, err);
363363
}
364364
})();
365+
366+
await (async () => {
367+
console.log('iterating on an ended stream completes');
368+
const r = new Readable({
369+
objectMode: true,
370+
read() {
371+
this.push('asdf');
372+
this.push('hehe');
373+
this.push(null);
374+
}
375+
});
376+
// eslint-disable-next-line no-unused-vars
377+
for await (const a of r) {
378+
}
379+
// eslint-disable-next-line no-unused-vars
380+
for await (const b of r) {
381+
}
382+
})();
365383
}
366384

367385
// to avoid missing some tests if a promise does not resolve

0 commit comments

Comments
 (0)