Skip to content

Commit

Permalink
stream: async iterator stop read if destroyed
Browse files Browse the repository at this point in the history
Fixes some compatibility issues where it is expected
that for await stops reading when the stream is
destroyed.

Refs: nodejs#34887
  • Loading branch information
ronag committed Oct 14, 2020
1 parent 999e7d7 commit 2c9432b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 1 addition & 1 deletion lib/internal/streams/readable.js
Expand Up @@ -1095,7 +1095,7 @@ async function* createAsyncIterator(stream) {

try {
while (true) {
const chunk = stream.read();
const chunk = stream.destroyed ? null : stream.read();
if (chunk !== null) {
yield chunk;
} else if (errorEmitted) {
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-stream-readable-async-iterators.js
Expand Up @@ -43,8 +43,6 @@ async function tests() {
});

const iter = Readable.prototype[Symbol.asyncIterator].call(stream);
await iter.next();
await iter.next();
await iter.next()
.then(common.mustNotCall())
.catch(common.mustCall((err) => {
Expand Down

0 comments on commit 2c9432b

Please sign in to comment.