Skip to content

Commit b856c87

Browse files
committed
Move queueMicroTask
1 parent 2d7a23d commit b856c87

File tree

9 files changed

+44
-44
lines changed

9 files changed

+44
-44
lines changed

files/en-us/_redirects.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8938,6 +8938,7 @@
89388938
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/indexedDB /en-US/docs/Web/API/indexedDB
89398939
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/isSecureContext /en-US/docs/Web/API/isSecureContext
89408940
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/origin /en-US/docs/Web/API/origin
8941+
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/queueMicrotask /en-US/docs/Web/API/queueMicrotask
89418942
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/rejectionhandled_event /en-US/docs/Web/API/Window/rejectionhandled_event
89428943
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/unhandledrejection_event /en-US/docs/Web/API/Window/unhandledrejection_event
89438944
/en-US/docs/Web/API/WindowSessionStorage /en-US/docs/Web/API/Window/sessionStorage

files/en-us/_wikihistory.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91808,16 +91808,6 @@
9180891808
"Bzbarsky"
9180991809
]
9181091810
},
91811-
"Web/API/WindowOrWorkerGlobalScope/queueMicrotask": {
91812-
"modified": "2020-10-15T22:21:06.789Z",
91813-
"contributors": [
91814-
"Kaiido",
91815-
"chrisdavidmills",
91816-
"Sheppy",
91817-
"zbjornson",
91818-
"DomenicDenicola"
91819-
]
91820-
},
9182191811
"Web/API/WindowOrWorkerGlobalScope/setInterval": {
9182291812
"modified": "2020-12-09T23:19:41.310Z",
9182391813
"contributors": [
@@ -95322,6 +95312,16 @@
9532295312
"ziyunfei"
9532395313
]
9532495314
},
95315+
"Web/API/queueMicrotask": {
95316+
"modified": "2020-10-15T22:21:06.789Z",
95317+
"contributors": [
95318+
"Kaiido",
95319+
"chrisdavidmills",
95320+
"Sheppy",
95321+
"zbjornson",
95322+
"DomenicDenicola"
95323+
]
95324+
},
9532595325
"Web/API/window/getDefaultComputedStyle": {
9532695326
"modified": "2020-10-15T21:20:40.098Z",
9532795327
"contributors": [

files/en-us/mozilla/firefox/releases/69/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ <h4 id="New_APIs">New APIs</h4>
112112

113113
<ul>
114114
<li>The <a href="/en-US/docs/Web/API/Resize_Observer_API">Resize Observer API</a> is supported by default ({{bug(1543839)}}).</li>
115-
<li>The Microtask API ({{domxref("WindowOrWorkerGlobalScope.queueMicrotask()")}}) has been implemented ({{bug(1480236)}}).</li>
115+
<li>The Microtask API ({{domxref("queueMicrotask()")}}) has been implemented ({{bug(1480236)}}).</li>
116116
</ul>
117117

118118
<h4 id="DOM">DOM</h4>

files/en-us/web/api/html_dom_api/microtask_guide/in_depth/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ <h2 id="See_also">See also</h2>
170170

171171
<ul>
172172
<li><a href="/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide">Microtask guide</a></li>
173-
<li>{{domxref("WindowOrWorkerGlobalScope.queueMicrotask", "queueMicrotask()")}}</li>
173+
<li>{{domxref("queueMicrotask()")}}</li>
174174
<li><a href="/en-US/docs/Learn/JavaScript/Asynchronous">Asynchronous JavaScript</a>
175175
<ul>
176176
<li><a href="/en-US/docs/Learn/JavaScript/Asynchronous/Concepts">General asynchronous programming concepts</a></li>

files/en-us/web/api/html_dom_api/microtask_guide/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<p>This event loop may be either the browser's main event loop or the event loop driving a <a href="/en-US/docs/Web/API/Web_Workers_API">web worker</a>. This lets the given function run without the risk of interfering with another script's execution, yet also ensures that the microtask runs before the user agent has the opportunity to react to actions taken by the microtask.</p>
2525

26-
<p>JavaScript <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promises</a> and the <a href="/en-US/docs/Web/API/MutationObserver">Mutation Observer API</a> both use the microtask queue to run their callbacks, but there are other times when the ability to defer work until the current event loop pass is wrapping up. In order to allow microtasks to be used by third-party libraries, frameworks, and polyfills, the {{domxref("WindowOrWorkerGlobalScope.queueMicrotask", "queueMicrotask()")}} method is exposed on the {{domxref("Window")}} and {{domxref("Worker")}} interfaces through the {{domxref("WindowOrWorkerGlobalScope")}} mixin.</p>
26+
<p>JavaScript <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promises</a> and the <a href="/en-US/docs/Web/API/MutationObserver">Mutation Observer API</a> both use the microtask queue to run their callbacks, but there are other times when the ability to defer work until the current event loop pass is wrapping up. In order to allow microtasks to be used by third-party libraries, frameworks, and polyfills, the {{domxref("queueMicrotask()")}} method is exposed on the {{domxref("Window")}} and {{domxref("Worker")}} interfaces through the {{domxref("WindowOrWorkerGlobalScope")}} mixin.</p>
2727

2828
<h2 id="Tasks_vs_microtasks">Tasks vs microtasks</h2>
2929

@@ -51,7 +51,7 @@ <h3 id="Microtasks">Microtasks</h3>
5151

5252
<p>First, each time a task exits, the event loop checks to see if the task is returning control to other JavaScript code. If not, it runs all of the microtasks in the microtask queue. The microtask queue is, then, processed multiple times per iteration of the event loop, including after handling events and other callbacks.</p>
5353

54-
<p>Second, if a microtask adds more microtasks to the queue by calling {{domxref("WindowOrWorkerGlobalScope.queueMicrotask", "queueMicrotask()")}}, those newly-added microtasks <em>execute before the next task is run</em>. That's because the event loop will keep calling microtasks until there are none left in the queue, even if more keep getting added.</p>
54+
<p>Second, if a microtask adds more microtasks to the queue by calling {{domxref("queueMicrotask()")}}, those newly-added microtasks <em>execute before the next task is run</em>. That's because the event loop will keep calling microtasks until there are none left in the queue, even if more keep getting added.</p>
5555

5656
<div class="notecard warning">
5757
<p><strong>Warning:</strong> Since microtasks can themselves enqueue more microtasks, and the event loop continues processing microtasks until the queue is empty, there's a real risk of getting the event loop endlessly processing microtasks. Be cautious with how you go about recursively adding microtasks.</p>
@@ -63,7 +63,7 @@ <h2 id="Using_microtasks">Using microtasks</h2>
6363

6464
<h3 id="Enqueueing_microtasks">Enqueueing microtasks</h3>
6565

66-
<p>As such, you should typically use microtasks only when there's no other solution, or when creating frameworks or libraries that need to use microtasks in order to create the functionality they're implementing. While there have been tricks available that made it possible to enqueue microtasks in the past (such as by creating a promise that resolves immediately), the addition of  the {{domxref("WindowOrWorkerGlobalScope.queueMicrotask", "queueMicrotask()")}} method adds a standard way to introduce a microtask safely and without tricks.</p>
66+
<p>As such, you should typically use microtasks only when there's no other solution, or when creating frameworks or libraries that need to use microtasks in order to create the functionality they're implementing. While there have been tricks available that made it possible to enqueue microtasks in the past (such as by creating a promise that resolves immediately), the addition of  the {{domxref("queueMicrotask()")}} method adds a standard way to introduce a microtask safely and without tricks.</p>
6767

6868
<p>By introducing <code>queueMicrotask()</code>, the quirks that arise when sneaking in using promises to create microtasks can be avoided. For instance, when using promises to create microtasks, exceptions thrown by the callback are reported as rejected promises rather than being reported as standard exceptions. Also, creating and destroying promises takes additional overhead both in terms of time and memory that a function which properly enqueues microtasks avoids.</p>
6969

@@ -205,7 +205,7 @@ <h4 id="JavaScript">JavaScript</h4>
205205
<pre class="brush: js hidden">let logElem = document.getElementById("log");
206206
let log = s =&gt; logElem.innerHTML += s + "&lt;br&gt;";</pre>
207207

208-
<p>In the following code, we see a call to {{domxref("WindowOrWorkerGlobalScope.queueMicrotask", "queueMicrotask()")}} used to schedule a microtask to run. This call is bracketed by calls to <code>log()</code>, a custom function that outputs text to the screen.</p>
208+
<p>In the following code, we see a call to {{domxref("queueMicrotask()")}} used to schedule a microtask to run. This call is bracketed by calls to <code>log()</code>, a custom function that outputs text to the screen.</p>
209209

210210
<pre class="brush: js">log("Before enqueueing the microtask");
211211
queueMicrotask(() =&gt; {
@@ -230,7 +230,7 @@ <h4 id="JavaScript_2">JavaScript</h4>
230230
let log = s =&gt; logElem.innerHTML += s + "&lt;br&gt;";</pre>
231231
</div>
232232

233-
<p>In the following code, we see a call to {{domxref("WindowOrWorkerGlobalScope.queueMicrotask", "queueMicrotask()")}} used to schedule a microtask to run. This call is bracketed by calls to <code>log()</code>, a custom function that outputs text to the screen.</p>
233+
<p>In the following code, we see a call to {{domxref("queueMicrotask()")}} used to schedule a microtask to run. This call is bracketed by calls to <code>log()</code>, a custom function that outputs text to the screen.</p>
234234

235235
<p>The code below schedules a timeout to occur in zero milliseconds, then enqueues a microtask. This is bracketed by calls to <code>log()</code> to output additional messages.</p>
236236

@@ -291,7 +291,7 @@ <h2 id="See_also">See also</h2>
291291

292292
<ul>
293293
<li><a href="/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide/In_depth">In depth: Microtasks and the JavaScript runtime environment</a></li>
294-
<li>{{domxref("WindowOrWorkerGlobalScope.queueMicrotask", "queueMicrotask()")}}</li>
294+
<li>{{domxref("queueMicrotask()")}}</li>
295295
<li><a href="/en-US/docs/Learn/JavaScript/Asynchronous">Asynchronous JavaScript</a>
296296
<ul>
297297
<li><a href="/en-US/docs/Learn/JavaScript/Asynchronous/Concepts">General asynchronous programming concepts</a></li>

files/en-us/web/api/windoworworkerglobalscope/queuemicrotask/index.html renamed to files/en-us/web/api/queuemicrotask/index.html

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
---
2-
title: WindowOrWorkerGlobalScope.queueMicrotask()
3-
slug: Web/API/WindowOrWorkerGlobalScope/queueMicrotask
2+
title: queueMicrotask()
3+
slug: Web/API/queueMicrotask
44
tags:
5-
- API
6-
- HTML DOM
7-
- Intervals
8-
- JavaScript
9-
- Method
10-
- Microtask
11-
- Performance
12-
- Reference
13-
- Scheduling
14-
- ServiceWorker
15-
- SharedWorker
16-
- Tasks
17-
- Timers
18-
- Window
19-
- WindowOrWorkerGlobalScope
20-
- Worker
21-
- asynchronous
22-
- queueMicrotask
23-
- setTimeout
24-
- Polyfill
25-
browser-compat: api.WindowOrWorkerGlobalScope.queueMicrotask
5+
- API
6+
- HTML DOM
7+
- Intervals
8+
- JavaScript
9+
- Method
10+
- Microtask
11+
- Performance
12+
- Reference
13+
- Scheduling
14+
- ServiceWorker
15+
- SharedWorker
16+
- Tasks
17+
- Timers
18+
- Window
19+
- Worker
20+
- asynchronous
21+
- queueMicrotask
22+
- setTimeout
23+
- Polyfill
24+
browser-compat: api.queueMicrotask
2625
---
2726
<div>{{APIRef("HTML DOM")}}</div>
2827

files/en-us/web/api/windoworworkerglobalscope/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h2 id="Methods">Methods</h2>
5555
<dd>Accepts a variety of different image sources, and returns a {{jsxref("Promise")}} which resolves to an {{domxref("ImageBitmap")}}. Optionally the source is cropped to the rectangle of pixels originating at <em>(</em><code>sx</code>, <code>sy</code><em>)</em> with width <code>sw</code>, and height <code>sh</code>.</dd>
5656
<dt>{{domxref("fetch()")}}</dt>
5757
<dd>Starts the process of fetching a resource from the network.</dd>
58-
<dt>{{domxref("WindowOrWorkerGlobalScope.queueMicrotask()")}}</dt>
58+
<dt>{{domxref("queueMicrotask()")}}</dt>
5959
<dd>Enqueues a microtask—a short function to be executed after execution of the JavaScript code completes and control isn't being returned to a JavaScript caller, but before handling callbacks and other tasks. This lets your code run without interfering with other, possibly higher priority, code, but <em>before</em> the browser runtime regains control, potentially depending upon the work you need to complete.</dd>
6060
<dt>{{domxref("WindowOrWorkerGlobalScope.setInterval()")}}</dt>
6161
<dd>Schedules a function to execute every time a given number of milliseconds elapses.</dd>

files/en-us/web/api/windoworworkerglobalscope/settimeout/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,5 @@ <h2 id="See_also">See also</h2>
363363
<li>{{domxref("clearTimeout")}}</li>
364364
<li>{{domxref("WindowOrWorkerGlobalScope.setInterval")}}</li>
365365
<li>{{domxref("window.requestAnimationFrame")}}</li>
366-
<li>{{domxref("WindowOrWorkerGlobalScope.queueMicrotask")}}</li>
366+
<li>{{domxref("queueMicrotask()")}}</li>
367367
</ul>

files/en-us/web/javascript/guide/using_promises/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ Using [`async`/`await`](/en-US/docs/Web/JavaScript/Reference/Statements/async_fu
394394

395395
If you run into situations in which you have promises and tasks (such as events or callbacks) which are firing in unpredictable orders, it's possible you may benefit from using a microtask to check status or balance out your promises when promises are created conditionally.
396396

397-
If you think microtasks may help solve this problem, see the [microtask guide](/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide) to learn more about how to use [`queueMicrotask()`](/en-US/docs/Web/API/WindowOrWorkerGlobalScope/queueMicrotask "The queueMicrotask() method, which is exposed on the Window or Worker interface, queues a microtask to be executed at a safe time prior to control returning to the browser's event loop.") to enqueue a function as a microtask.
397+
If you think microtasks may help solve this problem, see the [microtask guide](/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide) to learn more about how to use [`queueMicrotask()`](/en-US/docs/Web/API/queueMicrotask "The queueMicrotask() method, which is exposed on the Window or Worker interface, queues a microtask to be executed at a safe time prior to control returning to the browser's event loop.") to enqueue a function as a microtask.
398398

399399
## See also
400400

0 commit comments

Comments
 (0)