From 1dbacc007d4d0d1516784bc2aeea96f3af144390 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Thu, 2 Dec 2021 13:31:44 +0100 Subject: [PATCH] Editorial: Use the HTML spec's timers infrastructure for `timeout` In whatwg/html#7349, the HTML spec factored out part of the infrastructure for `setTimeout()` into a "run steps after a timeout" algorithm for use by other specs. This change updates `requestIdleCallback()` to use that algorithm when the `timeout` property is present and positive. --- index.html | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index 878f53f..5356053 100644 --- a/index.html +++ b/index.html @@ -314,38 +314,24 @@

The requestIdleCallback() method

idle callback identifier.
  • Push callback to the end of window's list of idle request callbacks, associated with handle.
  • -
  • Return handle and then continue running this algorithm - asynchronously. -

    The following steps run in parallel and queue a timer - similar to setTimeout() if the optional timeout property is - provided. From here, the idle and timeout callbacks are raced and - cancel each other—e.g. if the idle callback is scheduled first, then - it cancels the timeout callback, and vice versa.

    -
  • If the timeout property is present in options and has a positive - value: + value, then run steps after a timeout, given window, + "requestIdleCallback-timeout", timeout, and the + following step:
      -
    1. Wait for timeout milliseconds.
    2. -
    3. Wait until all invocations of this algorithm, whose - timeout added to their posted time occurred before this - one's, have completed.
    4. -
    5. Optionally, wait a further user-agent defined length of time. -

      This is intended to allow user agents to pad - timeouts as needed to optimise the power usage of the device. For - example, some processors have a low-power mode where the - granularity of timers is reduced; on such platforms, user agents - can slow timers down to fit this schedule instead of requiring - the processor to use the more accurate mode with its associated - higher power usage.

      -
    6. Queue a task on the queue associated with the idle-task task source, which performs the invoke idle callback timeout algorithm, passing handle and window as arguments.
    +

    This queues a timer similar to + setTimeout(). The idle and timeout callbacks are raced + and cancel each other—e.g. if the idle callback is scheduled first, + then it cancels the timeout callback, and vice versa.

  • +
  • Return handle.
  • {{Window/requestIdleCallback()}} only schedules a single callback, which will be executed during a