| | |
| | | * import async_hooks from 'async_hooks'; |
| | | * ``` |
| | | * @experimental |
| | | * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/async_hooks.js) |
| | | * @see [source](https://github.com/nodejs/node/blob/v17.0.0/lib/async_hooks.js) |
| | | */ |
| | | declare module 'async_hooks' { |
| | | /** |
| | |
| | | * @param type The type of async event. |
| | | * @param triggerAsyncId The ID of the execution context that created |
| | | * this async event (default: `executionAsyncId()`), or an |
| | | * AsyncResourceOptions object (since 9.3) |
| | | * AsyncResourceOptions object (since v9.3.0) |
| | | */ |
| | | constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions); |
| | | /** |
| | |
| | | getStore(): T | undefined; |
| | | /** |
| | | * Runs a function synchronously within a context and returns its |
| | | * return value. The store is not accessible outside of the callback function or |
| | | * the asynchronous operations created within the callback. |
| | | * return value. The store is not accessible outside of the callback function. |
| | | * The store is accessible to any asynchronous operations created within the |
| | | * callback. |
| | | * |
| | | * The optional `args` are passed to the callback function. |
| | | * |
| | |
| | | * try { |
| | | * asyncLocalStorage.run(store, () => { |
| | | * asyncLocalStorage.getStore(); // Returns the store object |
| | | * setTimeout(() => { |
| | | * asyncLocalStorage.getStore(); // Returns the store object |
| | | * }, 200); |
| | | * throw new Error(); |
| | | * }); |
| | | * } catch (e) { |