export class HeartbeatManager { private timers = new Map(); arm(jobId: string, timeoutMs: number, onTimeout: () => void): void { this.clear(jobId); const timer = setTimeout(onTimeout, timeoutMs); timer.unref(); this.timers.set(jobId, timer); } clear(jobId: string): void { const timer = this.timers.get(jobId); if (timer) { clearTimeout(timer); this.timers.delete(jobId); } } clearAll(): void { for (const jobId of this.timers.keys()) { this.clear(jobId); } } }