Dev Helpers
← Back

Exit a context temporarily

Exit a context temporarily using Node.js.

Open this example in the interactive library

Source code

import {
  AsyncLocalStorage,
  AsyncResource,
  executionAsyncId,
} from "node:async_hooks";
const context = new AsyncLocalStorage();
console.log(
  context.run("active", () =>
    context.exit(() => context.getStore() ?? "outside"),
  ),
);

Sample output

outside