feat: improve graceful shutdown — stop bg loop, drain fights, clear state

Shutdown now: 1) stops background fight loop, 2) waits up to 15s for
active fights to finish, 3) cancels pending human + poll challenges,
4) clears bet escrow. Added clearEscrow() to betting.ts. Tests verify
each cleanup function and shutdown sequence ordering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-13 09:53:39 +00:00
co-authored by Claude Opus 4.6
parent 023a1a58a9
commit 4134a27ea6
3 changed files with 130 additions and 4 deletions
+10
View File
@@ -165,6 +165,16 @@ export async function settleBets(
return settlements
}
/**
* Clear all escrow state (used during graceful shutdown).
* Returns the number of fights with open bets that were cleared.
*/
export function clearEscrow(): number {
const count = escrow.size
escrow.clear()
return count
}
/**
* Get all active bets for a fight.
*/