Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions files/en-us/web/api/idledeadline/timeremaining/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ browser-compat: api.IdleDeadline.timeRemaining
{{APIRef("Background Tasks")}}

The **`timeRemaining()`** method
on the {{domxref("IdleDeadline")}} interface returns the estimated number of
milliseconds remaining in the current idle period. The callback can call this method at
of the {{domxref("IdleDeadline")}} interface returns the estimated number of
milliseconds the user agent will remain idle for. The callback can call this method at
any time to determine how much time it can continue to work before it must return. For
example, if the callback finishes a task and has another one to begin, it can call
`timeRemaining()` to see if there's enough time to complete the next task. If
there isn't, the callback can just return immediately, or look for other work to do with
the remaining time.

By the time `timeRemaining()` reaches 0, it is suggested that the callback
By the time `timeRemaining()` reaches `0`, it is suggested that the callback
should return control to the user agent's event loop.

> [!NOTE]
> The value returned by `timeRemaining()` is an estimate of how much time the user agent believes is available before the next latency-critical task needs to run. This estimate is not fixed and can suddenly drop to 0 if higher-priority work arrives. For example, the browser's estimate can change in the middle of an idle callback if the user clicks. Developers should not assume the value always decreases linearly like a countdown timer.

## Syntax

```js-nolint
Expand Down
Loading