MCPcopy Create free account
hub / github.com/TanStack/db / requestIdleCallbackPolyfill

Function requestIdleCallbackPolyfill

packages/db/src/utils/browser-polyfills.ts:9–21  ·  view source on GitHub ↗
(
  callback: IdleCallbackFunction,
)

Source from the content-addressed store, hash-verified

7export type IdleCallbackFunction = (deadline: IdleCallbackDeadline) => void
8
9const requestIdleCallbackPolyfill = (
10 callback: IdleCallbackFunction,
11): number => {
12 // Use a very small timeout for the polyfill to simulate idle time
13 const timeout = 0
14 const timeoutId = setTimeout(() => {
15 callback({
16 didTimeout: true, // Always indicate timeout for the polyfill
17 timeRemaining: () => 50, // Return some time remaining for polyfill
18 })
19 }, timeout)
20 return timeoutId as unknown as number
21}
22
23const cancelIdleCallbackPolyfill = (id: number): void => {
24 clearTimeout(id as unknown as ReturnType<typeof setTimeout>)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected