Skip to content

Commit

Permalink
Fix microtask usage guide code example (#38176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena authored Feb 16, 2025
1 parent 2e6d901 commit e5a5e11
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions files/en-us/web/api/html_dom_api/microtask_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The main reason to use microtasks is that: to ensure consistent ordering of task
One situation in which microtasks can be used to ensure that the ordering of execution is always consistent is when promises are used in one clause of an `if...else` statement (or other conditional statement), but not in the other clause. Consider code such as this:

```js
customElement.prototype.getData = (url) => {
customElement.prototype.getData = function (url) {
if (this.cache[url]) {
this.data = this.cache[url];
this.dispatchEvent(new Event("load"));
Expand Down Expand Up @@ -122,7 +122,7 @@ Even worse, sometimes the element's `data` property will be set and other times
We can ensure consistent ordering of these operations by using a microtask in the `if` clause to balance the two clauses:

```js
customElement.prototype.getData = (url) => {
customElement.prototype.getData = function (url) {
if (this.cache[url]) {
queueMicrotask(() => {
this.data = this.cache[url];
Expand Down

0 comments on commit e5a5e11

Please sign in to comment.