Hyperlinkv0.8.0-beta.28

Pool

Pool.invalidateconsteffect/Pool.ts:509
<A>(item: A): <E>(
  self: Pool<A, E>
) => Effect.Effect<void, never, Scope.Scope>
<A, E>(self: Pool<A, E>, item: A): Effect.Effect<void, never, Scope.Scope>

Invalidates the specified item so the pool can remove it and reallocate the item, lazily if needed.

When to use

Use to prevent a pooled item from being reused after it becomes unsuitable, such as a stale connection or a resource that failed a health check.

Gotchas

The item is matched with strict equality. Passing an equivalent but different object instance does nothing.

combinatorsget
Source effect/Pool.ts:50914 lines
export const invalidate: {
  <A>(item: A): <E>(self: Pool<A, E>) => Effect.Effect<void, never, Scope.Scope>
  <A, E>(self: Pool<A, E>, item: A): Effect.Effect<void, never, Scope.Scope>
} = dual(2, <A, E>(self: Pool<A, E>, item: A): Effect.Effect<void, never, Scope.Scope> =>
  Effect.suspend(() => {
    if (self.state.isShuttingDown) return Effect.void
    for (const poolItem of self.state.items) {
      if (poolItem.exit._tag === "Success" && poolItem.exit.value === item) {
        poolItem.disableReclaim = true
        return Effect.uninterruptible(invalidatePoolItem(self, poolItem))
      }
    }
    return Effect.void
  }))