Easier to control requestIdleCallbacks with fallback support for environments without requestIdleCallback (either for browsers which don't have support or for node).
// e.g. a sync function, supports experimental deadline if needed functionsomeHeavyFunc(deadline: IdleDeadline) { while (deadline.timeRemaining() > 0 && tasks.length > 0) { process(tasks.shift()); } }
const { trigger, callImmediately, cancelPendingCallbacks, isPending } = createIdleCallback( someHeavyFunc, { timeout:2000 }, // if you need to update a reactive variable in your framework, e.g. vue (_) =>isPending.value = _ )
// above by itself does nothing, you must call trigger to queue the request trigger() // cancels any pending and requests idle callback
Easier to control requestIdleCallbacks with fallback support for environments without requestIdleCallback (either for browsers which don't have support or for node).
Returns { trigger, cancelPendingCallbacks, callImmediately, isPending }.