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:
parent
a9051bb2c3
commit
9c48926dba
@ -58,7 +58,7 @@ function onError(iter, err) {
|
||||
iter[kLastReject] = null;
|
||||
reject(err);
|
||||
}
|
||||
iter.error = err;
|
||||
iter[kError] = err;
|
||||
}
|
||||
|
||||
function wrapForNext(lastPromise, iter) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user