MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / poll

Function poll

src/stores/syncResultPolling.ts:46–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 let polling = false
45
46 const poll = async () => {
47 if (stopped || polling) return
48 polling = true
49 try {
50 const sources = await options.loadDataSources()
51 if (stopped) return
52
53 const nextStates = buildSessionStateMap(sources)
54 if (previousStates) {
55 const completed = sources.some((source) =>
56 source.sessions.some((session) => {
57 const key = `${source.id}:${session.id}`
58 return session.lastStatus !== 'idle' && previousStates?.get(key) !== nextStates.get(key)
59 })
60 )
61 if (completed) await options.onResult()
62 }
63 previousStates = nextStates
64 } catch {
65 // 临时请求失败时保留旧基线,下次成功轮询仍可检测期间发生的同步结果。
66 } finally {
67 polling = false
68 }
69 }
70
71 void poll()
72 const timer = schedule(() => void poll(), options.intervalMs ?? 5000)

Callers 1

createSyncResultPollerFunction · 0.85

Calls 2

buildSessionStateMapFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected