MCPcopy
hub / github.com/Effect-TS/effect / makeCancel

Function makeCancel

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…