I my experience every use of requestIdleCallback will eventually have a wrapper like this one:
function requestIdleCallback(win, minimumTimeRemaining, timeout, fn) {
const before = Date.now();
win.requestIdleCallback(info => {
if (info.timeRemaining() < minimumTimeRemaining) {
const remainingTimeout = timeout - (Date.now() - before);
if (remainingTimeout <= 0) {
fn();
} else {
requestIdleCallback(win, minimumTimeRemaining, remainingTimeout, fn);
}
} else {
fn();
}
});
}
…where rIC is called recursively until a time budget under some requirement is reached. Among other things this requires managing the timeout in user code, because one will typically want a timeout across these calls.
This would be fixed by allowing the caller to pass in something like minimumTimeRemaining into the rIC options object.
I my experience every use of
requestIdleCallbackwill eventually have a wrapper like this one:…where rIC is called recursively until a time budget under some requirement is reached. Among other things this requires managing the timeout in user code, because one will typically want a timeout across these calls.
This would be fixed by allowing the caller to pass in something like
minimumTimeRemaininginto the rIC options object.