Function
watchdogTimer
(
createTimer: CreateTimerImpl,
pollInterval: number,
anrThreshold: number,
callback: () => void,
)
Source from the content-addressed store, hash-verified
| 19 | * @returns An object with `poll` and `enabled` functions {@link WatchdogReturn} |
| 20 | */ |
| 21 | export function watchdogTimer( |
| 22 | createTimer: CreateTimerImpl, |
| 23 | pollInterval: number, |
| 24 | anrThreshold: number, |
| 25 | callback: () => void, |
| 26 | ): WatchdogReturn { |
| 27 | const timer = createTimer(); |
| 28 | let triggered = false; |
| 29 | let enabled = true; |
| 30 | |
| 31 | setInterval(() => { |
| 32 | const diffMs = timer.getTimeMs(); |
| 33 | |
| 34 | if (triggered === false && diffMs > pollInterval + anrThreshold) { |
| 35 | triggered = true; |
| 36 | if (enabled) { |
| 37 | callback(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | if (diffMs < pollInterval + anrThreshold) { |
| 42 | triggered = false; |
| 43 | } |
| 44 | }, 20); |
| 45 | |
| 46 | return { |
| 47 | poll: () => { |
| 48 | timer.reset(); |
| 49 | }, |
| 50 | enabled: (state: boolean) => { |
| 51 | enabled = state; |
| 52 | }, |
| 53 | }; |
| 54 | } |
| 55 | |
| 56 | // types copied from inspector.d.ts |
| 57 | interface Location { |
Tested by
no test coverage detected