blob: e4074e727703e416a536b4e164d4ee9bb3cbdfd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
---
title: IdleDeadline.timeRemaining()
slug: Web/API/IdleDeadline/timeRemaining
translation_of: Web/API/IdleDeadline/timeRemaining
---
<p>{{APIRef("Background Tasks")}}{{SeeCompatTable}}</p>
<p>The <code><strong>timeRemaining</strong></code><strong><code>()</code></strong> 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 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 <code>timeRemaining()</code> 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.</p>
<p>By the time <code>timeRemaining()</code> reaches 0, it is suggested that the callback should return control to the user agent's event loop.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox notranslate"><em>timeRemaining</em> = <em>IdleDeadline</em>.timeRemaining();
</pre>
<h3 id="Return_value">Return value</h3>
<p>A {{domxref("DOMHighResTimeStamp")}} value (which is a floating-point number) representing the number of milliseconds the user agent estimates are left in the current idle period. The value is ideally accurate to within about 5 microseconds.</p>
<p>If the {{domxref("IdleDeadline")}} object's {{domxref("IdleDeadline.didTimeout", "didTimeout")}} property is true, this method returns zero.</p>
<h2 id="Example">Example</h2>
<p>See our <a href="/en-US/docs/Web/API/Background_Tasks_API#Example">complete example</a> in the article <a href="/en-US/docs/Web/API/Background_Tasks_API">Cooperative Scheduling of Background Tasks API</a>.</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName("Background Tasks")}}</td>
<td>{{Spec2("Background Tasks")}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("api.IdleDeadline.timeRemaining")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/API/Background_Tasks_API">Collaborative Scheduling of Background Tasks</a></li>
<li>{{domxref("IdleDeadline")}}</li>
<li>{{domxref("Window.requestIdleCallback()")}}</li>
<li>{{domxref("Window.cancelIdleCallback()")}}</li>
</ul>
|