mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 08:03:28 +00:00
Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import { scheduleSharedControlReconnect } from './remote-runtime-shared-control-state'
|
|
|
|
export class SharedControlReconnectScheduler {
|
|
private timer: ReturnType<typeof setTimeout> | null = null
|
|
private attempt = 0
|
|
|
|
get isScheduled(): boolean {
|
|
return this.timer !== null
|
|
}
|
|
|
|
get attemptCount(): number {
|
|
return this.attempt
|
|
}
|
|
|
|
schedule(args: {
|
|
intentionallyClosed: boolean
|
|
delaysMs: readonly number[]
|
|
open: () => void
|
|
}): void {
|
|
// Why: a passive subscription owns recovery until its caller closes it; roaming outages are unbounded.
|
|
const scheduled = scheduleSharedControlReconnect({
|
|
...args,
|
|
current: this.timer,
|
|
reconnectAttempt: this.attempt,
|
|
open: () => {
|
|
this.timer = null
|
|
args.open()
|
|
}
|
|
})
|
|
this.timer = scheduled.timer
|
|
this.attempt = scheduled.reconnectAttempt
|
|
}
|
|
|
|
clear(): void {
|
|
if (this.timer) {
|
|
clearTimeout(this.timer)
|
|
this.timer = null
|
|
}
|
|
}
|
|
|
|
clearWhenIdle(isIdle: boolean): void {
|
|
if (isIdle) {
|
|
this.clear()
|
|
}
|
|
}
|
|
|
|
resetAttempt(): void {
|
|
this.attempt = 0
|
|
}
|
|
}
|