aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/idledeadline/timeremaining
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/idledeadline/timeremaining
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/idledeadline/timeremaining')
-rw-r--r--files/zh-cn/web/api/idledeadline/timeremaining/index.html59
1 files changed, 59 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/idledeadline/timeremaining/index.html b/files/zh-cn/web/api/idledeadline/timeremaining/index.html
new file mode 100644
index 0000000000..e4074e7277
--- /dev/null
+++ b/files/zh-cn/web/api/idledeadline/timeremaining/index.html
@@ -0,0 +1,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>