@@ -96435,8 +96435,8 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
96435
96435
<p class="note">For entries put in the <span>map of active timers</span> by the <span>timer
96436
96436
initialization steps</span>, i.e., by <code data-x="dom-setTimeout">setTimeout()</code> and <code
96437
96437
data-x="dom-setInterval">setInterval()</code>, the keys are numbers. For other specifications
96438
- that use the <span>wait for a timeout</span> algorithm, the identifier is a unique non-numeric
96439
- value. Only the numeric-keyed timers are affected by <code
96438
+ that use the <span>run steps after a timeout</span> algorithm, the identifier is a unique
96439
+ non-numeric value. Only the numeric-keyed timers are affected by <code
96440
96440
data-x="dom-clearTimeout">clearTimeout()</code> and <code
96441
96441
data-x="dom-clearInterval">clearInterval()</code>, but all timers contribute to <a
96442
96442
href="#idle-deadline-computation">idle deadline computation</a>, and are cleared when the
@@ -96483,8 +96483,8 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
96483
96483
96484
96484
<li><p>If <var>previousId</var> was given, let <var>id</var> be <var>previousId</var>;
96485
96485
otherwise, let <var>id</var> be an <span>implementation-defined</span> integer that is greater
96486
- than zero that will identify the timeout to be set by this call in <var>global</var>'s <span>map
96487
- of active timers</span>.</p></li>
96486
+ than zero and does not already <span data-x="map exists">exist</span> in <var>global</var>'s
96487
+ <span>map of active timers</span>.</p></li>
96488
96488
96489
96489
<li>
96490
96490
<p>If the <span>surrounding agent</span>'s <span data-x="concept-agent-event-loop">event
@@ -96594,14 +96594,14 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
96594
96594
<var>global</var> to run <var>task</var>.</p></li>
96595
96595
96596
96596
<li>
96597
- <p><span>Wait for a timeout</span> given <var>global</var>, "<code
96597
+ <p><span>Run steps after a timeout</span> given <var>global</var>, "<code
96598
96598
data-x="">setTimeout/setInterval</code>", <var>timeout</var>, <var>completionStep</var>, and
96599
- <var>handle </var>.</p>
96599
+ <var>id </var>.</p>
96600
96600
96601
96601
<p class="note">Once the task has been processed, if <var>repeat</var> is false, it is safe to
96602
- remove the entry for <var>handle </var> from the <span>map of active timers</span> (there is no
96603
- way for the entry's existence to be detected past this point, so it does not technically matter
96604
- one way or the other).</p>
96602
+ remove the entry for <var>id </var> from the <span>map of active timers</span> (there is no way
96603
+ for the entry's existence to be detected past this point, so it does not technically matter one
96604
+ way or the other).</p>
96605
96605
</li>
96606
96606
96607
96607
<li><p>Return <var>id</var>.</p></li>
@@ -96624,7 +96624,38 @@ setTimeout({ toString: function () {
96624
96624
} }, 100);</code></pre>
96625
96625
</div>
96626
96626
96627
- <p>To <dfn export>wait for a timeout</dfn>, given a <code>WindowOrWorkerGlobalScope</code>
96627
+ </div>
96628
+
96629
+ <div class="example">
96630
+ <p>To run tasks of several milliseconds back to back without any delay, while still yielding back
96631
+ to the browser to avoid starving the user interface (and to avoid the browser killing the script
96632
+ for hogging the CPU), simply queue the next timer before performing work:</p>
96633
+
96634
+ <pre><code class="js">function doExpensiveWork() {
96635
+ var done = false;
96636
+ // ...
96637
+ // this part of the function takes up to five milliseconds
96638
+ // set done to true if we're done
96639
+ // ...
96640
+ return done;
96641
+ }
96642
+
96643
+ function rescheduleWork() {
96644
+ var id = setTimeout(rescheduleWork, 0); // preschedule next iteration
96645
+ if (doExpensiveWork())
96646
+ clearTimeout(id); // clear the timeout if we don't need it
96647
+ }
96648
+
96649
+ function scheduleWork() {
96650
+ setTimeout(rescheduleWork, 0);
96651
+ }
96652
+
96653
+ scheduleWork(); // queues a task to do lots of work</code></pre>
96654
+ </div>
96655
+
96656
+ <div w-nodev>
96657
+
96658
+ <p>To <dfn export>run steps after a timeout</dfn>, given a <code>WindowOrWorkerGlobalScope</code>
96628
96659
<var>global</var>, a string <var>orderingIdentifier</var>, a number <var>milliseconds</var>, a
96629
96660
set of steps <var>completionSteps</var>, and an optional value <var>timerKey</var>:</p>
96630
96661
@@ -96633,7 +96664,8 @@ setTimeout({ toString: function () {
96633
96664
<span>timer initialization steps</span>. (Other specifications must not pass
96634
96665
<var>timerKey</var>.)</p></li>
96635
96666
96636
- <li><p>If <var>timerKey</var> is not given, set it to a new unique non-numeric value.</p></li>
96667
+ <li><p>If <var>timerKey</var> is not given, then set it to a new unique non-numeric
96668
+ value.</p></li>
96637
96669
96638
96670
<li><p>Let <var>startTime</var> be the <span>current high resolution time</span>.</p></li>
96639
96671
@@ -96675,40 +96707,14 @@ setTimeout({ toString: function () {
96675
96707
</li>
96676
96708
</ol>
96677
96709
96678
- <p class="note"><span>Wait for a timeout</span> is meant to be used by other specifications that
96679
- want to wait on developer-supplied timeouts, in a similar manner to <code
96680
- data-x="dom-setTimeout">setTimeout()</code>. (Note, however, it does not have the nesting and
96681
- clamping behavior of <code data-x="dom-setTimeout">setTimeout()</code>.) Such specifications can
96682
- choose an <var>orderingIdentifier</var> to ensure ordering within their specification's timeouts,
96683
- while not constraining ordering with respect to other specification's timeouts.</p>
96684
-
96685
- </div>
96686
-
96687
- <div class="example">
96688
- <p>To run tasks of several milliseconds back to back without any delay, while still yielding back
96689
- to the browser to avoid starving the user interface (and to avoid the browser killing the script
96690
- for hogging the CPU), simply queue the next timer before performing work:</p>
96691
-
96692
- <pre><code class="js">function doExpensiveWork() {
96693
- var done = false;
96694
- // ...
96695
- // this part of the function takes up to five milliseconds
96696
- // set done to true if we're done
96697
- // ...
96698
- return done;
96699
- }
96700
-
96701
- function rescheduleWork() {
96702
- var id = setTimeout(rescheduleWork, 0); // preschedule next iteration
96703
- if (doExpensiveWork())
96704
- clearTimeout(id); // clear the timeout if we don't need it
96705
- }
96710
+ <p class="note"><span>Run steps after a timeout</span> is meant to be used by other
96711
+ specifications that want to execute developer-supplied code after a developer-supplied timeout,
96712
+ in a similar manner to <code data-x="dom-setTimeout">setTimeout()</code>. (Note, however, it does
96713
+ not have the nesting and clamping behavior of <code data-x="dom-setTimeout">setTimeout()</code>.)
96714
+ Such specifications can choose an <var>orderingIdentifier</var> to ensure ordering within their
96715
+ specification's timeouts, while not constraining ordering with respect to other specification's
96716
+ timeouts.</p>
96706
96717
96707
- function scheduleWork() {
96708
- setTimeout(rescheduleWork, 0);
96709
- }
96710
-
96711
- scheduleWork(); // queues a task to do lots of work</code></pre>
96712
96718
</div>
96713
96719
96714
96720
0 commit comments