MCPcopy Create free account
hub / github.com/TanStack/query / createCoalescedSchedule

Function createCoalescedSchedule

packages/query-devtools/src/Devtools.tsx:2215–2229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2213 * @returns The `schedule` function to pass to a registry's `notify`.
2214 */
2215const createCoalescedSchedule = () => {
2216 const pendingUpdates = new Map<symbol, () => void>()
2217 const flush = () => {
2218 const updates = [...pendingUpdates.values()]
2219 pendingUpdates.clear()
2220 batch(() => {
2221 updates.forEach((update) => update())
2222 })
2223 }
2224 onCleanup(() => pendingUpdates.clear())
2225 return (update: () => void, id: symbol) => {
2226 if (!pendingUpdates.size) queueMicrotask(flush)
2227 pendingUpdates.set(id, update)
2228 }
2229}
2230
2231const setupQueryCacheSubscription = () => {
2232 const { queryCacheSubscriptions } = useDevtoolsSubscriptions()

Callers 2

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected