Skip to content
File

Blob: src/node/internal/async_hooks.d.ts

typescript34 lines
1// Copyright (c) 2026 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5// Type definitions for c++ implementation.
6 
7export interface AsyncResourceOptions {
8 triggerAsyncId?: number;
9}
10 
11export class AsyncResource {
12 constructor(type: string, options?: AsyncResourceOptions);
13 runInAsyncScope<R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R;
14 
15 bind<Func extends (...args: unknown[]) => unknown>(
16 fn: Func
17 ): Func & { asyncResource: AsyncResource };
18 
19 static bind<
20 Func extends (this: ThisArg, ...args: unknown[]) => unknown,
21 ThisArg,
22 >(
23 fn: Func,
24 type?: string,
25 thisArg?: ThisArg
26 ): Func & { asyncResource: AsyncResource };
27}
28 
29export class AsyncLocalStorage<T> {
30 run<R>(store: T, fn: (...args: unknown[]) => R, ...args: unknown[]): R;
31 exit<R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R;
32 getStore(): T;
33}