MCPcopy Create free account
hub / github.com/Effect-TS/effect / make

Function make

packages/effect/src/RcMap.ts:250–287  ·  view source on GitHub ↗
(options: {
  readonly lookup: (key: K) => Effect.Effect<A, E, R>
  readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined
  readonly capacity?: number | undefined
})

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

constantFunction · 0.90
clearMethod · 0.80
makeUnsafeFunction · 0.70
getMethod · 0.65
pipeMethod · 0.65
forEachMethod · 0.65
closeMethod · 0.65
syncMethod · 0.45

Tested by

no test coverage detected