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

Function makeCancel

packages/sql-pg/src/PgClient.ts:531–550  ·  view source on GitHub ↗
(pool: Pg.Pool, client: Pg.PoolClient)

Source from the content-addressed store, hash-verified

529
530const cancelEffects = new WeakMap<Pg.PoolClient, Effect.Effect<void> | undefined>()
531const makeCancel = (pool: Pg.Pool, client: Pg.PoolClient) => {
532 if (cancelEffects.has(client)) {
533 return cancelEffects.get(client)!
534 }
535 const processId = (client as any).processID
536 const eff = processId !== undefined
537 // query cancelation is best-effort, so we don't fail if it doesn't work
538 ? Effect.async<void>((resume) => {
539 if (pool.ending) return resume(Effect.void)
540 pool.query(`SELECT pg_cancel_backend(${processId})`, () => {
541 resume(Effect.void)
542 })
543 }).pipe(
544 Effect.interruptible,
545 Effect.timeoutOption(5000)
546 )
547 : undefined
548 cancelEffects.set(client, eff)
549 return eff
550}
551
552/**
553 * @category layers

Callers 1

runWithClientMethod · 0.85

Calls 4

getMethod · 0.65
pipeMethod · 0.65
setMethod · 0.65
resumeFunction · 0.50

Tested by

no test coverage detected