Phase 9: Faster Write-Back (CAL-15) — event-driven outbox drain #14

Merged
luckberg merged 26 commits from gsd/phase-09-faster-write-back into main 2026-06-12 21:19:17 -04:00
Showing only changes of commit 8307a7b713 - Show all commits
+10 -2
View File
@@ -23,10 +23,18 @@ const emitter = new EventEmitter();
/**
* Fire a drain signal after a successful outbox enqueue commit.
* Synchronous and fire-and-forget — never awaited (D-04).
* Fire-and-forget — never awaited (D-04).
*
* WR-01: the emit is deferred to a microtask so the registered listener
* (scheduleOutboxDrain) never runs on the enqueue caller's stack. EventEmitter.emit
* dispatches listeners synchronously; without this defer, any synchronous throw in
* the listener chain would propagate back into the route handler's try/catch and
* surface a misleading 503 for an enqueue that actually committed. Deferring keeps
* the documented decoupling honest: a misbehaving listener can never corrupt the
* route response.
*/
export function signalOutboxDrain(): void {
emitter.emit('drain');
queueMicrotask(() => emitter.emit('drain'));
}
/**