Are functions passed to requestIdleCallback
guaranteed to run when no timeout
is specified? (Assuming we aren't in some contrived scenario, specifically engineered to avoid idle state indefinitiely)
And if a timeout
is specified, is there a guarantee around order of execution? e.g.
const options = { timeout: 10000 };
requestIdleCallback(fnOne, options);
requestIdleCallback(fnTwo, options);
requestIdleCallback(fnThree, options);
Are fnOne
, fnTwo
, and fnThree
guaranteed to be invoke in that order every time?
Cooperative Scheduling of Background Tasks says:
During an idle period the user agent will run idle callbacks in FIFO order until either the idle period ends or there are no more idle callbacks eligible to be run. As such, the user agent will not necessarily run all currently posted idle callbacks within a single idle period. Any remaining idle tasks are eligible to run during the next idle period.
Therefore, I believe with your example, fnOne
, fnTwo
and fnThree
would be executed in that order.