Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5ea25c2

Browse filesBrowse files
mcollinaMylesBorins
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 dbd37ab commit 5ea25c2
Copy full SHA for 5ea25c2

File tree

Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/async_iterator.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/async_iterator.js
+4-1Lines changed: 4 additions & 1 deletion
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
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-stream-readable-async-iterators.js
+18Lines changed: 18 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.