| 251 | * Uses the ContextMap's shared semaphore for safe single initialization. |
| 252 | */ |
| 253 | export const cachedPerRequest = <A, E, R>( |
| 254 | make: Effect.Effect<A, E, R> |
| 255 | ): Effect.Effect<A, E | ContextMapNotStartedError, R> => { |
| 256 | const cacheKey = Symbol() |
| 257 | return getContextMap.pipe( |
| 258 | Effect.flatMap((ctxMap) => ctxMap.getOrCreateStoreEffect(cacheKey, make)) |
| 259 | ) |
| 260 | } |
| 261 | |
| 262 | const defaultNs: NonEmptyString255 = NonEmptyString255("primary") |
| 263 | export class storeId extends Context.Reference("StoreId", { defaultValue: (): NonEmptyString255 => defaultNs }) {} |