Skip to content

Commit 2c9432b

Browse files
committed
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: nodejs#34887
1 parent 999e7d7 commit 2c9432b

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

lib/internal/streams/readable.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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)