( parent: Fiber.Fiber<unknown, unknown>, map: MutableHashMap.MutableHashMap<K, Entry<A, E>>, capacity: number )
| 388 | }) |
| 389 | |
| 390 | const checkCapacity = <K, A, E>( |
| 391 | parent: Fiber.Fiber<unknown, unknown>, |
| 392 | map: MutableHashMap.MutableHashMap<K, Entry<A, E>>, |
| 393 | capacity: number |
| 394 | ): Effect.Effect<void> => { |
| 395 | if (!Number.isFinite(capacity)) return effect.void |
| 396 | let diff = MutableHashMap.size(map) - capacity |
| 397 | if (diff <= 0) return effect.void |
| 398 | // MutableHashMap has insertion order, so we can remove the oldest entries |
| 399 | const fibers = Arr.empty<Fiber.Fiber<unknown, unknown>>() |
| 400 | for (const [key, entry] of map) { |
| 401 | MutableHashMap.remove(map, key) |
| 402 | fibers.push(effect.forkUnsafe(parent as any, closeEvicted(entry), true)) |
| 403 | diff-- |
| 404 | if (diff === 0) break |
| 405 | } |
| 406 | return effect.fiberAwaitAll(fibers) |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Reads an existing unexpired cache entry without running the lookup function. |
no test coverage detected