Effect CommunityEC
Effect Community•3y ago•
6 replies
wyattjoh

Using Effect to Simplify Running Effects within AsyncLocalStorage

Question! I'm interested in using effect to wrap a AsyncLocalStorage instance so I can simplify running effects within it's context. Specifically, I wanted to do something like:

type Store = { color?: string }
const storage = new AsyncLocalStorage<Store>()
const RenderContextResource = Effect.acquireUseRelease(
  Effect.succeed({} as Store),
  (store) => {
    storage.run(store, () => {
      // run the effect that "used" this resource here somehow...
    })
  },
  (ctx) => {
    // ?
  },
)


But I'm unsure how it's possible to "run" the effects that "use" the resource within the callback... Thoughts?
Was this page helpful?