MCPcopy Create free account
hub / github.com/Effect-TS/effect / withChildScope

Function withChildScope

packages/sql/pg/src/PgPool.ts:322–333  ·  view source on GitHub ↗
(
    f: (
      scope: Scope.Closeable,
      restore: <X, E, R>(effect: Effect.Effect<X, E, R>) => Effect.Effect<X, E, R>
    ) => Effect.Effect<A, SqlError>
  )

Source from the content-addressed store, hash-verified

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.

Callers 2

PgPool.tsFile · 0.85
withAcquireTimeoutFunction · 0.85

Calls 4

onErrorMethod · 0.80
closeMethod · 0.65
fFunction · 0.50
getUnsafeMethod · 0.45

Tested by

no test coverage detected