summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/async_hooks.ts8
-rw-r--r--tests/unit_node/async_hooks_test.ts17
2 files changed, 25 insertions, 0 deletions
diff --git a/ext/node/polyfills/async_hooks.ts b/ext/node/polyfills/async_hooks.ts
index e69bc88aa..d60334346 100644
--- a/ext/node/polyfills/async_hooks.ts
+++ b/ext/node/polyfills/async_hooks.ts
@@ -308,6 +308,14 @@ export class AsyncLocalStorage {
const currentFrame = AsyncContextFrame.current();
return currentFrame.get(this.#key);
}
+
+ enterWith(store: unknown) {
+ const frame = AsyncContextFrame.create(
+ null,
+ new StorageEntry(this.#key, store),
+ );
+ Scope.enter(frame);
+ }
}
export function executionAsyncId() {
diff --git a/tests/unit_node/async_hooks_test.ts b/tests/unit_node/async_hooks_test.ts
index 5457b4d19..076d14b54 100644
--- a/tests/unit_node/async_hooks_test.ts
+++ b/tests/unit_node/async_hooks_test.ts
@@ -77,3 +77,20 @@ Deno.test(async function nested() {
assertEquals(await deferred.promise, { x: 1 });
assertEquals(await deferred1.promise, null);
});
+
+Deno.test(async function enterWith() {
+ const als = new AsyncLocalStorage();
+ const deferred = Promise.withResolvers();
+ const deferred1 = Promise.withResolvers();
+
+ als.run(null, () => {
+ als.run({ x: 1 }, () => {
+ als.enterWith({ x: 2 });
+ deferred.resolve(als.getStore());
+ });
+ deferred1.resolve(als.getStore());
+ });
+
+ assertEquals(await deferred.promise, { x: 2 });
+ assertEquals(await deferred1.promise, { x: 1 });
+});