Mutation observers use them to debounce mutation callbacks. Promises use them to ensure promise callbacks don't happen in the middle of other script.
-
-
Replying to @jaffathecake @gauntface
They're the answer to "what do you call the opportunity to run code after all the synchronous stuff but before yielding to the event loop?"
3 replies 0 retweets 7 likes -
I'm still a little confused about the microtasks executing between the two click handlers example. Is the idea that when one function finishes running it checks to see if any microtasks are enqueued, runs them, then moves on to the next function?
1 reply 0 retweets 0 likes -
Replying to @rob_dodson @slightlylate and
for context, referring to this bit:https://youtu.be/cCOL7MC4Pl0?t=30m4s …
1 reply 0 retweets 0 likes -
Replying to @rob_dodson @slightlylate and
the reason i'm confused is because it isn't quite at the point of yielding back to the event loop because we're still processing functions related to the same event. it's more like it's taking a breath between each function
2 replies 0 retweets 0 likes -
Microtasks run when JS finishes running, as in the JS stack goes from having something in it, to nothing. That happens between listeners when dispatching an event.
1 reply 0 retweets 3 likes -
Replying to @jaffathecake @rob_dodson and
I see a lot of articles that say microtasks happen "in the next turn of the loop", which isn't right. Microtasks are more closely related to JS than the event loop.
1 reply 0 retweets 3 likes -
Replying to @jaffathecake @rob_dodson and
Microtasks are also processed after each task, but generally you'll encounter them when the JS stack empties.
1 reply 0 retweets 2 likes -
Right. Yielding back to the event loop *also* requires an empty stack, so that just falls out naturally.
2 replies 0 retweets 0 likes -
Replying to @slightlylate @jaffathecake and
The code for this has nice comments that document what's going on: https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/bindings/Microtask.h?type=cs&l=41 …
2 replies 0 retweets 4 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
& Web Standards TL; Blink API OWNER
Named PWAs w/
DMs open. Tweets my own; press@google.com for official comms.