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: keep async context of pipeTo watchers · nodejs/node@d5fa3be

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/webstreams
    • readablestream.js
  • test/parallel
    • test-whatwg-webstreams-async-context.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/readablestream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const {
4747
DOMException,
4848
} = internalBinding('messaging');
4949

50+
const AsyncContextFrame = require('internal/async_context_frame');
51+
5052
const {
5153
isArrayBufferView,
5254
isDataView,
@@ -1547,21 +1549,30 @@ function readableStreamFromIterable(iterable) {
15471549
// record enqueues the watcher at the microtask position a reaction on the
15481550
// promise would have had, without materializing the promise; the shared
15491551
// pending promise satisfies the probes on the erroring/release paths.
1552+
// The reaction is registered in the async context captured at install
1553+
// time, where the spec registers it, rather than in the context of
1554+
// whoever settles the record.
15501555
class ClosedPromiseHook {
15511556
constructor(onResolved, onRejected) {
15521557
this.promise = kPendingPromise;
15531558
this.onResolved = onResolved;
15541559
this.onRejected = onRejected;
1560+
this.contextFrame = AsyncContextFrame.current();
15551561
}
15561562

15571563
resolve() {
1558-
if (this.onResolved !== undefined)
1559-
PromisePrototypeThen(kResolvedPromise, this.onResolved);
1564+
if (this.onResolved === undefined)
1565+
return;
1566+
const prior = AsyncContextFrame.exchange(this.contextFrame);
1567+
PromisePrototypeThen(kResolvedPromise, this.onResolved);
1568+
AsyncContextFrame.set(prior);
15601569
}
15611570

15621571
reject(error) {
15631572
const onRejected = this.onRejected;
1573+
const prior = AsyncContextFrame.exchange(this.contextFrame);
15641574
PromisePrototypeThen(kResolvedPromise, () => onRejected(error));
1575+
AsyncContextFrame.set(prior);
15651576
}
15661577
}
15671578

0 commit comments

Comments
0 (0)
You are visitor 01402775 — 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.