| 7 | export type IdleCallbackFunction = (deadline: IdleCallbackDeadline) => void |
| 8 | |
| 9 | const 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 | |
| 23 | const cancelIdleCallbackPolyfill = (id: number): void => { |
| 24 | clearTimeout(id as unknown as ReturnType<typeof setTimeout>) |