Elide fournit AsyncLocalStorage, AsyncResource, createHook,
executionAsyncId, triggerAsyncId, executionAsyncResource et
asyncWrapProviders.
AsyncLocalStorage prend en charge run, exit, getStore, enterWith,
disable, snapshot et bind. La propagation du contexte est partielle : le
code synchrone et une minuterie créée dans run peuvent observer le store,
mais pas une continuation de Promise.
import { AsyncLocalStorage } from "node:async_hooks";
const storage = new AsyncLocalStorage();
storage.run("request", () => {
console.log(storage.getStore()); // request
Promise.resolve().then(() => {
console.log(storage.getStore()); // undefined
});
});createHook() renvoie un objet doté de enable() et disable(), mais Elide ne
fournit pas le cycle de vie complet des ressources asynchrones de Node. Les
bibliothèques qui ont besoin du contexte à travers await ne doivent pas
s’appuyer sur cette implémentation.
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: 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.