(pool: Pg.Pool, client: Pg.PoolClient)
| 530 | |
| 531 | const cancelEffects = new WeakMap<Pg.PoolClient, Effect.Effect<void> | undefined>() |
| 532 | const 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 |
no test coverage detected
searching dependent graphs…