| 49 | } |
| 50 | |
| 51 | class Scheduler { |
| 52 | private interval: NodeJS.Timeout | null = null; |
| 53 | private latches = new Set<TimeoutLatch>(); |
| 54 | |
| 55 | add(latch: TimeoutLatch): void { |
| 56 | this.latches.add(latch); |
| 57 | this.start(); |
| 58 | } |
| 59 | |
| 60 | remove(latch: TimeoutLatch): void { |
| 61 | this.latches.delete(latch); |
| 62 | if (this.latches.size === 0) { |
| 63 | this.stop(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | private start(): void { |
| 68 | if (this.interval === null) { |
| 69 | this.interval = setInterval(() => { |
| 70 | this.latches.forEach((latch) => { |
| 71 | latch.tick(); |
| 72 | if (latch.isDone) { |
| 73 | this.remove(latch); |
| 74 | } |
| 75 | }); |
| 76 | }, 1); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | private stop(): void { |
| 81 | if (this.interval !== null) { |
| 82 | clearInterval(this.interval); |
| 83 | this.interval = null; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | let globalScheduler: Scheduler | null = null; |
| 89 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…