From 8eb2b6c61f9fdac12f8bab23ad3e9ef71c7c59b1 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Tue, 2 Apr 2024 17:53:29 -0500 Subject: feat: improve AsyncLocalStorage api (#23175) Fixes: https://github.com/denoland/deno/issues/23174 --- ext/node/polyfills/async_hooks.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ext/node/polyfills/async_hooks.ts') diff --git a/ext/node/polyfills/async_hooks.ts b/ext/node/polyfills/async_hooks.ts index d60334346..ea0bfb944 100644 --- a/ext/node/polyfills/async_hooks.ts +++ b/ext/node/polyfills/async_hooks.ts @@ -316,6 +316,17 @@ export class AsyncLocalStorage { ); Scope.enter(frame); } + + static bind(fn: (...args: unknown[]) => unknown) { + return AsyncResource.bind(fn); + } + + static snapshot() { + return AsyncLocalStorage.bind(( + cb: (...args: unknown[]) => unknown, + ...args: unknown[] + ) => cb(...args)); + } } export function executionAsyncId() { -- cgit v1.2.3