| 320 | // Runs `f` uninterruptibly in a child scope, closing it on failure or |
| 321 | // interruption so acquired resources are returned instead of left on the caller. |
| 322 | const withChildScope = <A>( |
| 323 | f: ( |
| 324 | scope: Scope.Closeable, |
| 325 | restore: <X, E, R>(effect: Effect.Effect<X, E, R>) => Effect.Effect<X, E, R> |
| 326 | ) => Effect.Effect<A, SqlError> |
| 327 | ): Effect.Effect<A, SqlError, Scope.Scope> => |
| 328 | Effect.uninterruptibleMask((restore) => |
| 329 | Effect.withFiber((fiber) => { |
| 330 | const scope = Scope.forkUnsafe(Context.getUnsafe(fiber.context, Scope.Scope)) |
| 331 | return Effect.onError(f(scope, restore), (cause) => Scope.close(scope, Exit.failCause(cause))) |
| 332 | }) |
| 333 | ) |
| 334 | |
| 335 | // One checkout attempt (`undefined` if rejected). Closes the attempt scope |
| 336 | // before retrying so the rejected transport frees its slot first. |