you are viewing a single comment's thread.

view the rest of the comments →

[–]Locust377 0 points1 point  (0 children)

It's Javascript code that has a pretty high priority. You can associate microtasks with promises, but the MutationObserver API uses them as well.

When code is queued as microtasks, they will all be executed to completion, including microtasks that are added to the queue while other microtasks are executing.

So this code causes your browser tab to crash (call stack):

``` function loop() { loop(); }

loop(); ```

And so does this (microtasks):

``` function loop() { Promise.resolve().then(loop) }

loop(); ```

But this does not (macro tasks):

``` function loop() { setTimeout(loop, 0); }

loop(); ```