In Workers, the only thing that's isolated is within your `fetch` handler which is it's own "asynchr

In Workers, the only thing that's isolated is within your
fetch
handler which is it's own "asynchronous duration" - it's an async function, basically called by the runtime.

When you call als.run(..., async () => { ... }); inside your
fetch
handler, als keeps track of what context it was called in (this specific call of the
fetch
handler).

When your other modules are calling als.getStore(), those modules were called within that run callback - it's tied to that invocation of the
fetch
handler.

If you tried calling als.getStore() within the
fetch
handler but outside of the run callback, it'd be
undefined
. run stores what you pass to it in a context that's only available to the callback, and other calls to run by other requests doesn't mutate our store since als knows that is a separate invocation of the
fetch
handler.
Was this page helpful?