stream: fix error handling with async iteration

Fix an issue when an error was emitted by the stream before
`iterator.next()` is called.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Julien Fontanet 2018-04-26 11:53:23 +02:00 committed by Ruben Bridgewater
parent a9051bb2c3
commit 9c48926dba
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 13 additions and 1 deletions

View File

@ -58,7 +58,7 @@ function onError(iter, err) {
iter[kLastReject] = null;
reject(err);
}
iter.error = err;
iter[kError] = err;
}
function wrapForNext(lastPromise, iter) {

View File

@ -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;