GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: fix async iterator destroyed error propagation · nodejs/node@499c41d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams
    • async_iterator.js
  • test/parallel
    • test-stream-readable-async-iterators.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/async_iterator.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/async_iterator.js
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,20 @@ const ReadableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({
7878
}
7979

8080
if (this[kStream].destroyed) {
81-
// We need to defer via nextTick because if .destroy(err) is
82-
// called, the error will be emitted via nextTick, and
83-
// we cannot guarantee that there is no error lingering around
84-
// waiting to be emitted.
8581
return new Promise((resolve, reject) => {
86-
process.nextTick(() => {
87-
if (this[kError]) {
88-
reject(this[kError]);
89-
} else {
90-
resolve(createIterResult(undefined, true));
91-
}
92-
});
82+
if (this[kError]) {
83+
reject(this[kError]);
84+
} else if (this[kEnded]) {
85+
resolve(createIterResult(undefined, true));
86+
} else {
87+
finished(this[kStream], (err) => {
88+
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
89+
reject(err);
90+
} else {
91+
resolve(createIterResult(undefined, true));
92+
}
93+
});
94+
}
9395
});
9496
}
9597

Collapse file

‎test/parallel/test-stream-readable-async-iterators.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-readable-async-iterators.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,23 @@ async function tests() {
484484
assert.strictEqual(e, err);
485485
})()]);
486486
}
487+
488+
{
489+
const _err = new Error('asd');
490+
const r = new Readable({
491+
read() {
492+
},
493+
destroy(err, callback) {
494+
setTimeout(() => callback(_err), 1);
495+
}
496+
});
497+
498+
r.destroy();
499+
const it = r[Symbol.asyncIterator]();
500+
it.next().catch(common.mustCall((err) => {
501+
assert.strictEqual(err, _err);
502+
}));
503+
}
487504
}
488505

489506
{

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.