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

Function drainAborted

packages/sql/pg/src/PgConnection.ts:1932–1955  ·  view source on GitHub ↗
(
  conn: PgConnectionImpl,
  timeoutMessage: string,
  abort: (onDrained: () => void) => void
)

Source from the content-addressed store, hash-verified

1930
1931/** Drains an aborted statement, sending a cancel after a short grace period and failing if it stalls. */
1932const drainAborted = (
1933 conn: PgConnectionImpl,
1934 timeoutMessage: string,
1935 abort: (onDrained: () => void) => void
1936): Effect.Effect<void> => {
1937 const drained = Deferred.makeUnsafe<void>()
1938 const timeout = setTimeout(
1939 () => conn.fatal(connectionQueryError(new Error(timeoutMessage), `PgConnection: ${timeoutMessage}`)),
1940 abortDrainTimeoutMillis
1941 )
1942 abort(() => {
1943 clearTimeout(timeout)
1944 Deferred.doneUnsafe(drained, Effect.void)
1945 })
1946 const grace = Effect.callback<void>((resume) => {
1947 const timer = setTimeout(() => resume(Effect.void), abortDrainGraceMillis)
1948 return Effect.sync(() => clearTimeout(timer))
1949 })
1950 const cancelAndDrain = Effect.andThen(conn.cancel, Deferred.await(drained))
1951 return Effect.andThen(
1952 Effect.raceFirst(Deferred.await(drained), grace),
1953 Effect.suspend(() => Deferred.isDoneUnsafe(drained) ? Effect.void : cancelAndDrain)
1954 )
1955}
1956
1957/** One cycle on a connection that carries a single statement at a time. */
1958const runQuery = (

Callers 2

runQueryFunction · 0.85
streamRowsFunction · 0.85

Calls 6

connectionQueryErrorFunction · 0.85
fatalMethod · 0.80
awaitMethod · 0.65
abortFunction · 0.50
resumeFunction · 0.50
syncMethod · 0.45

Tested by

no test coverage detected