| 248 | readonly capacity: number |
| 249 | }): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R> |
| 250 | } = <K, A, E, R>(options: { |
| 251 | readonly lookup: (key: K) => Effect.Effect<A, E, R> |
| 252 | readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined |
| 253 | readonly capacity?: number | undefined |
| 254 | }) => |
| 255 | Effect.withFiber<RcMap<K, A, E>, never, R | Scope.Scope>((fiber) => { |
| 256 | const context = fiber.context as Context.Context<R | Scope.Scope> |
| 257 | const scope = Context.get(context, Scope.Scope) |
| 258 | const self = makeUnsafe<K, A, E>({ |
| 259 | lookup: options.lookup as any, |
| 260 | context, |
| 261 | scope, |
| 262 | idleTimeToLive: typeof options.idleTimeToLive === "function" |
| 263 | ? flow(options.idleTimeToLive, Duration.fromInputUnsafe) |
| 264 | : constant(Duration.fromInputUnsafe(options.idleTimeToLive ?? Duration.zero)), |
| 265 | capacity: Math.max(options.capacity ?? Number.POSITIVE_INFINITY, 0) |
| 266 | }) |
| 267 | return Effect.as( |
| 268 | Scope.addFinalizerExit(scope, () => { |
| 269 | if (self.state._tag === "Closed") { |
| 270 | return Effect.void |
| 271 | } |
| 272 | const map = self.state.map |
| 273 | self.state = { _tag: "Closed" } |
| 274 | return Effect.forEach( |
| 275 | map, |
| 276 | ([, entry]) => Effect.exit(Scope.close(entry.scope, Exit.void)) |
| 277 | ).pipe( |
| 278 | Effect.tap(() => |
| 279 | Effect.sync(() => { |
| 280 | MutableHashMap.clear(map) |
| 281 | }) |
| 282 | ) |
| 283 | ) |
| 284 | }), |
| 285 | self |
| 286 | ) |
| 287 | }) |
| 288 | |
| 289 | /** |
| 290 | * Gets the resource for a key, acquiring it with the map's lookup function when |