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?
-
-
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 -
Thanks! I understood the stack bit after watching Jake's example again. I think mentally i imagined each handler was part of a larger stack, called by some uber handleAllTheClickThings process. And that process would have to finish before microtasks could run.
1 reply 0 retweets 0 likes -
Replying to @rob_dodson @slightlylate and
but really each handler is an independent stack that gets built up, finishes, microtasks run, then the next handler goes and creates its stack, and eventually it's all empty and we yield back
1 reply 0 retweets 1 like
All the meat is here: https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/dom/events/EventTarget.cpp?type=cs&l=682 …
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.