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: #34887

PR-URL: #35640
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
ronag authored and MylesBorins committed Oct 15, 2020
1 parent bfc9069 commit 1d8ecd8
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 1d8ecd8

Please sign in to comment.