MCPcopy Create free account
hub / github.com/Effect-TS/effect / startIdle

Function startIdle

packages/effect/src/ui/Query.ts:5674–5693  ·  view source on GitHub ↗
(entry: Entry)

Source from the content-addressed store, hash-verified

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.

Callers 2

afterQuietFunction · 0.85
storeWriteFunction · 0.85

Calls 5

cancelIdleFunction · 0.85
idleTtlFunction · 0.85
removeEntryFunction · 0.70
nowFunction · 0.70
sleepFunction · 0.70

Tested by

no test coverage detected