(self: Pool<A, E>, poolItem: PoolItem<A, E>)
| 1039 | }) |
| 1040 | |
| 1041 | const invalidatePoolItem = <A, E>(self: Pool<A, E>, poolItem: PoolItem<A, E>): Effect.Effect<void> => |
| 1042 | Effect.suspend(() => { |
| 1043 | if (!self.state.items.has(poolItem)) { |
| 1044 | return Effect.void |
| 1045 | } else if (poolItem.refCount === 0) { |
| 1046 | self.state.items.delete(poolItem) |
| 1047 | removeAvailable(self, poolItem) |
| 1048 | self.state.invalidated.delete(poolItem) |
| 1049 | return Effect.asVoid(Effect.flatMap( |
| 1050 | poolItem.finalizer, |
| 1051 | () => Effect.forkIn(Effect.interruptible(resize(self)), self.state.scope, { startImmediately: true }) |
| 1052 | )) |
| 1053 | } |
| 1054 | self.state.invalidated.add(poolItem) |
| 1055 | removeAvailable(self, poolItem) |
| 1056 | // An invalidated item stops counting towards the pool's active size, so the |
| 1057 | // pool is now below target and has to top itself back up. Waiting for the |
| 1058 | // last lease to be returned would strand anybody already queued: the item |
| 1059 | // they are waiting for is never coming back. |
| 1060 | return Effect.asVoid( |
| 1061 | Effect.forkIn(Effect.interruptible(resize(self)), self.state.scope, { startImmediately: true }) |
| 1062 | ) |
| 1063 | }) |
| 1064 | |
| 1065 | // `failures` is the failure count when a borrower requested the resize or the |
| 1066 | // previous pass ran. Startup and invalidation refills omit it. |
no test coverage detected