(options: {
readonly lookup: (key: K) => Effect<A, E, R>
readonly idleTimeToLive?: Duration.DurationInput | ((key: K) => Duration.DurationInput) | undefined
readonly capacity?: number | undefined
})
| 83 | readonly capacity: number |
| 84 | }): Effect<RcMap.RcMap<K, A, E | Cause.ExceededCapacityException>, never, Scope.Scope | R> |
| 85 | } = <K, A, E, R>(options: { |
| 86 | readonly lookup: (key: K) => Effect<A, E, R> |
| 87 | readonly idleTimeToLive?: Duration.DurationInput | ((key: K) => Duration.DurationInput) | undefined |
| 88 | readonly capacity?: number | undefined |
| 89 | }) => |
| 90 | core.withFiberRuntime<RcMap.RcMap<K, A, E>, never, R | Scope.Scope>((fiber) => { |
| 91 | const context = fiber.getFiberRef(core.currentContext) as Context.Context<R | Scope.Scope> |
| 92 | const scope = Context.get(context, fiberRuntime.scopeTag) |
| 93 | const idleTimeToLive = options.idleTimeToLive === undefined |
| 94 | ? undefined |
| 95 | : typeof options.idleTimeToLive === "function" |
| 96 | ? flow(options.idleTimeToLive, Duration.decode) |
| 97 | : constant(Duration.decode(options.idleTimeToLive)) |
| 98 | const self = new RcMapImpl<K, A, E>( |
| 99 | options.lookup as any, |
| 100 | context, |
| 101 | scope, |
| 102 | idleTimeToLive, |
| 103 | Math.max(options.capacity ?? Number.POSITIVE_INFINITY, 0) |
| 104 | ) |
| 105 | return core.as( |
| 106 | scope.addFinalizer(() => |
| 107 | core.suspend(() => { |
| 108 | if (self.state._tag === "Closed") { |
| 109 | return core.void |
| 110 | } |
| 111 | const map = self.state.map |
| 112 | self.state = { _tag: "Closed" } |
| 113 | return core.forEachSequentialDiscard( |
| 114 | map, |
| 115 | ([, entry]) => core.scopeClose(entry.scope, core.exitVoid) |
| 116 | ).pipe( |
| 117 | core.tap(() => { |
| 118 | MutableHashMap.clear(map) |
| 119 | }), |
| 120 | self.semaphore.withPermits(1) |
| 121 | ) |
| 122 | }) |
| 123 | ), |
| 124 | self |
| 125 | ) |
| 126 | }) |
| 127 | |
| 128 | /** @internal */ |
| 129 | export const get: { |
nothing calls this directly
no test coverage detected