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

Function borrow

packages/sql/pg/src/PgPool.ts:247–265  ·  view source on GitHub ↗
(
    counted: "traced" | "untraced" | "any",
    f: (leave: () => void) => Effect.Effect<A, E, R>
  )

Source from the content-addressed store, hash-verified

245 // stop counting before user callbacks so they cannot suppress background spans.
246 const borrowers = { traced: 0, untraced: 0 }
247 const borrow = <A, E, R>(
248 counted: "traced" | "untraced" | "any",
249 f: (leave: () => void) => Effect.Effect<A, E, R>
250 ): Effect.Effect<A, E, R> =>
251 Effect.withFiber((fiber) => {
252 const kind = fiber.cache.tracerEnabled ? "traced" : "untraced"
253 if (counted !== "any" && counted !== kind) return f(constVoid)
254 return Effect.uninterruptibleMask((restore) => {
255 let counting = true
256 const leave = () => {
257 if (counting) {
258 counting = false
259 borrowers[kind]--
260 }
261 }
262 borrowers[kind]++
263 return Effect.ensuring(restore(f(leave)), Effect.sync(leave))
264 })
265 })
266 const acquire = Effect.uninterruptibleMask((restore) => {
267 // Closed once: on connect failure/interruption or when the transport closes.
268 const permit = Scope.makeUnsafe()

Callers 3

PgClient.tsFile · 0.70
PgPool.tsFile · 0.70
useFunction · 0.70

Calls 3

fFunction · 0.50
restoreFunction · 0.50
syncMethod · 0.45

Tested by

no test coverage detected