Skip to content

Commit 1d8ecd8

Browse files
ronagMylesBorins
authored andcommitted
stream: async iterator stop read if destroyed
Fixes some compatibility issues where it is expected that for await stops reading when the stream is destroyed. Refs: #34887 PR-URL: #35640 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bfc9069 commit 1d8ecd8

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

lib/internal/streams/readable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ async function* createAsyncIterator(stream) {
10951095

10961096
try {
10971097
while (true) {
1098-
const chunk = stream.read();
1098+
const chunk = stream.destroyed ? null : stream.read();
10991099
if (chunk !== null) {
11001100
yield chunk;
11011101
} else if (errorEmitted) {

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

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ async function tests() {
4343
});
4444

4545
const iter = Readable.prototype[Symbol.asyncIterator].call(stream);
46-
await iter.next();
47-
await iter.next();
4846
await iter.next()
4947
.then(common.mustNotCall())
5048
.catch(common.mustCall((err) => {

0 commit comments

Comments
 (0)