http/pending_effects.ts view source
(ctx: EmitAfterCommitContext, fn: () => void | Promise<void>): void Defer a side effect until after the handler's transaction commits.
Pushes a raw thunk onto ctx.post_commit_effects — the flush
middleware (in server/app_server.ts and the per-message WS dispatcher)
is the only site that ever invokes fn. This is load-bearing: a
previous implementation queued Promise.resolve().then(fn), which
JS's microtask scheduler drains before the wrapping
await db.query('COMMIT') resumes — fn fired mid-transaction and a
rollback would leak a notification for state that never landed.
The thunk shape closes that gap by deferring the work to flush time.
The flush owns the per-thunk try/catch + log.error so any
directly-pushed thunk (tests included) cannot escape the safety net.
ctx
context carrying log and the post_commit_effects queue
fn
side effect to run after commit; may return void or Promise<void>
() => void | Promise<void>returns
void