Skip to content

Allow requesting a minimum time budget #49

@cramforce

Description

@cramforce

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions