( parent: Fiber.Fiber<unknown, unknown>, map: MutableHashMap.MutableHashMap<K, Entry<A, E>>, capacity: number )
| 302 | } |
| 303 | |
| 304 | const checkCapacity = <K, A, E>( |
| 305 | parent: Fiber.Fiber<unknown, unknown>, |
| 306 | map: MutableHashMap.MutableHashMap<K, Entry<A, E>>, |
| 307 | capacity: number |
| 308 | ): Effect.Effect<void> => { |
| 309 | if (!Number.isFinite(capacity)) return effect.void |
| 310 | let diff = MutableHashMap.size(map) - capacity |
| 311 | if (diff <= 0) return effect.void |
| 312 | // MutableHashMap has insertion order, so we can remove the oldest entries |
| 313 | const fibers = Arr.empty<Fiber.Fiber<unknown, unknown>>() |
| 314 | for (const [key, entry] of map) { |
| 315 | MutableHashMap.remove(map, key) |
| 316 | fibers.push(effect.forkUnsafe(parent as any, Scope.close(entry.scope, effect.exitVoid), true)) |
| 317 | diff-- |
| 318 | if (diff === 0) break |
| 319 | } |
| 320 | return effect.fiberAwaitAll(fibers) |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Reads an existing unexpired cache entry without running the lookup function. |
no test coverage detected