MCPcopy Create free account
hub / github.com/experdot/pointer / enqueue

Function enqueue

src/renderer/src/stores/persistenceQueue.ts:82–109  ·  view source on GitHub ↗
(key: TKey, data: TData)

Source from the content-addressed store, hash-verified

80 const writing = new Map<TKey, Promise<void>>()
81
82 function enqueue(key: TKey, data: TData): void {
83 const now = Date.now()
84 const current = pending.get(key)
85 const mergedData = current && mergePending ? mergePending(current.data, data) : data
86 pending.set(key, { data: mergedData, timestamp: current?.timestamp ?? now })
87
88 if (!firstQueueTime.has(key)) {
89 firstQueueTime.set(key, now)
90 }
91
92 const existingTimer = timers.get(key)
93 if (existingTimer) {
94 clearTimeout(existingTimer)
95 }
96
97 const firstTime = firstQueueTime.get(key) ?? now
98 const elapsed = now - firstTime
99
100 if (elapsed >= maxDelayMs) {
101 void flush(key)
102 } else {
103 const delay = Math.min(debounceMs, maxDelayMs - elapsed)
104 const timer = setTimeout(() => {
105 void flush(key)
106 }, delay)
107 timers.set(key, timer)
108 }
109 }
110
111 async function flush(key: TKey): Promise<void> {
112 const timer = timers.get(key)

Callers 1

useMessageQueueFunction · 0.85

Calls 3

flushFunction · 0.85
hasMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected