# node:async_hooks

> How Elide supports Node's `async_hooks`: AsyncLocalStorage, AsyncResource and createHook, and where AsyncLocalStorage context does not propagate.

`node:async_hooks` provides `AsyncLocalStorage`, `AsyncResource`, and `createHook` from
[Node's `async_hooks`](https://nodejs.org/api/async_hooks.html).

## Example

```js
import { AsyncLocalStorage } from "node:async_hooks";

const storage = new AsyncLocalStorage();
storage.run("request", async () => {
  await null;
  console.log(storage.getStore()); // request
  queueMicrotask(() => console.log(storage.getStore())); // undefined
});
```

## Differences from Node

- `AsyncLocalStorage` context is lost in `queueMicrotask` callbacks and `node:fs` callbacks.
- `createHook` callbacks (`init`, `before`, `after`, `destroy`) fire for timers, immediates, and Promise continuations.

<!-- api-reference:start 6e95af6a7301 -->
## Reference

**Status:** Partial · 36 of 45 suite tests pass (80.0%) · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `async_hooks` | module | Partial | hooks fire for timers/immediates/promises but not yet for TCP/HTTP/TLS native resources |
| `createHook()` | function | Full | Creates a new AsyncHook instance |
| `executionAsyncId()` | function | Full | Returns the asyncId of the current execution context |
| `triggerAsyncId()` | function | Full | Returns the ID of the resource responsible for calling the callback that is currently being executed |
| `AsyncLocalStorage` | property | Full | The AsyncLocalStorage class |
| `AsyncResource` | property | Full | The AsyncResource class |

**Tests:** [node-api `node:async-hooks`](https://github.com/elide-dev/testsuite/blob/main/reports/1.6.0%2B6e718933f/4cbcae6c33a8/node-api/node-api.md): 36 pass, 8 fail, 1 error, 3 skipped. Failing: `test-async-hooks-destroy-on-gc.js`, `test-async-hooks-enable-recursive.js`, `test-async-hooks-fatal-error.js`, `test-async-hooks-http-parser-destroy.js`, `test-async-hooks-top-level-clearimmediate.js`, `test-async-local-storage-http-agent.js`, `test-async-local-storage-http-multiclients.js`, `test-async-local-storage-http-parser-leak.js`, and 1 more.
<!-- api-reference:end -->
