(entry: Entry)
| 5672 | const idleTtl = (entry: Entry): number => entry.def.idleMs ?? defaultIdleMs |
| 5673 | // Built like `RcMap`'s: an `expiresAt` a reset moves, and a sleep that goes round again. |
| 5674 | const startIdle = (entry: Entry): void => { |
| 5675 | cancelIdle(entry) |
| 5676 | // The server starts no idle timers. |
| 5677 | if (settleOnce) return |
| 5678 | const ttl = idleTtl(entry) |
| 5679 | if (ttl === Infinity) return |
| 5680 | if (ttl <= 0) return removeEntry(entry) |
| 5681 | const idle: Idle = { expiresAt: now() + ttl, cancel: () => {} } |
| 5682 | entry.idle = idle |
| 5683 | const sleep = (ms: number): void => { |
| 5684 | idle.cancel = timer(ms, () => { |
| 5685 | if (entry.idle !== idle) return |
| 5686 | const remaining = idle.expiresAt - now() |
| 5687 | if (remaining > 0) return sleep(remaining) |
| 5688 | entry.idle = undefined |
| 5689 | if (idleEligible(entry)) removeEntry(entry) |
| 5690 | }) |
| 5691 | } |
| 5692 | sleep(ttl) |
| 5693 | } |
| 5694 | /** Called whenever the entry may have gone quiet: removes a cold one, starts the timer on a settled one. */ |
| 5695 | const afterQuiet = (entry: Entry): void => { |
| 5696 | // Called after the entry's emission, so a run's wait ends after its watchers have seen the settle. |
no test coverage detected