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

Function makeCancel

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

Source from the content-addressed store, hash-verified

766
767const cancelEffects = new WeakMap<Pg.PoolClient, Effect.Effect<void> | undefined>()
768const makeCancel = (pool: Pg.Pool, client: Pg.PoolClient) => {
769 if (cancelEffects.has(client)) {
770 return cancelEffects.get(client)!
771 }
772 const processId = (client as any).processID
773 const eff = processId !== undefined
774 // query cancelation is best-effort, so we don't fail if it doesn't work
775 ? Effect.callback<void>((resume) => {
776 if (pool.ending) return resume(Effect.void)
777 pool.query(`SELECT pg_cancel_backend(${processId})`, () => {
778 resume(Effect.void)
779 })
780 }).pipe(
781 Effect.interruptible,
782 Effect.timeoutOption(5000)
783 )
784 : undefined
785 cancelEffects.set(client, eff)
786 return eff
787}
788
789/**
790 * Creates a layer from an effect that acquires a `PgClient`, providing both `PgClient` and `SqlClient`.

Callers 1

makeConectionFunction · 0.85

Calls 5

getMethod · 0.65
pipeMethod · 0.65
setMethod · 0.65
resumeFunction · 0.50
hasMethod · 0.45

Tested by

no test coverage detected