Skip to content

Commit

Permalink
stream: fix error handling with async iteration
Browse files Browse the repository at this point in the history
Fix an issue when an error was emitted by the stream before
`iterator.next()` is called.

PR-URL: nodejs#20329
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
julien-f authored and BridgeAR committed Apr 29, 2018
1 parent a9051bb commit 9c48926
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/streams/async_iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function onError(iter, err) {
iter[kLastReject] = null;
reject(err);
}
iter.error = err;
iter[kError] = err;
}

function wrapForNext(lastPromise, iter) {
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-stream-readable-async-iterators.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ async function tests() {
readable.destroy(new Error('kaboom'));
})();

await (async function() {
console.log('call next() after error');
const readable = new Readable({
read() {}
});
const iterator = readable[Symbol.asyncIterator]();

const err = new Error('kaboom');
readable.destroy(new Error('kaboom'));
await assert.rejects(iterator.next.bind(iterator), err);
})();

await (async function() {
console.log('read object mode');
const max = 42;
Expand Down

0 comments on commit 9c48926

Please sign in to comment.