http/pending_effects.ts

Shared post-commit side-effect helper.

WS sends and on_audit_event SSE broadcasts must never fire mid-transaction — a rollback would leak state that never existed. Anything pushed onto pending_effects runs after the response is sent (see the request-context middleware), so this helper is the canonical home for post-commit fan-out.

Satisfied by both RouteContext (HTTP routes) and ActionContext (RPC actions) — they share {log, pending_effects} by convention, so this module stays in http/ (both depend on it).

Declarations
#

2 declarations

view source

emit_after_commit
#

http/pending_effects.ts view source

(ctx: PendingEffectsContext, fn: () => void): void

Defer a side effect until after the handler's transaction commits.

Exceptions thrown by fn are caught and logged via ctx.log.error, so one failed send cannot corrupt the already-committed response or starve other queued effects in the same tick.

ctx

context carrying log and the pending_effects queue

fn

synchronous side effect to run after commit

type () => void

returns

void

PendingEffectsContext
#

Imported by
#