Skip to content

Commit

Permalink
stream: ended streams should resolve the async iteration
Browse files Browse the repository at this point in the history
Fixes: #23891
  • Loading branch information
mcollina committed Oct 26, 2018
1 parent 6223236 commit 6f5c14f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/streams/async_iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ const createReadableStreamAsyncIterator = (stream) => {
[kLastResolve]: { value: null, writable: true },
[kLastReject]: { value: null, writable: true },
[kError]: { value: null, writable: true },
[kEnded]: { value: false, writable: true },
[kEnded]: {
value: stream._readableState.endEmitted,
writable: true
},
[kLastPromise]: { value: null, writable: true },
// the function passed to new Promise
// is cached so we avoid allocating a new
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-stream-readable-async-iterators.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@ async function tests() {
assert.strictEqual(e, err);
}
})();

await (async () => {
console.log('iterating on an ended stream completes');
const r = new Readable({
objectMode: true,
read() {
this.push('asdf');
this.push('hehe');
this.push(null);
}
});
// eslint-disable-next-line no-unused-vars
for await (const a of r) {
}
// eslint-disable-next-line no-unused-vars
for await (const b of r) {
}
})();
}

// to avoid missing some tests if a promise does not resolve
Expand Down

0 comments on commit 6f5c14f

Please sign in to comment.