Dev Helpers
← Back

Restore an outer context

Restore an outer context 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("outer", () => [
    context.run("inner", () => context.getStore()),
    context.getStore(),
  ]),
);

Sample output

[ 'inner', 'outer' ]