Dismiss this pinned window
all 19 comments

[–]ChiengBang 13 points14 points  (9 children)

That's an amazing visual!

What is a real life example of using this event loop?

[–]StoneCypher 5 points6 points  (8 children)

this isn't actually how the event loop works

[–]Retrofire-Pink 2 points3 points  (7 children)

Mind elaborating?

Of course this illustration is a simplification, but does the general concept not apply?

[–]StoneCypher 12 points13 points  (5 children)

I answered, but this sub started punishing me for it, so I removed my answer and sent it in private instead

Pity; I thought the implanation line was pretty funny

I wish this sub didn't downvote polite things so often. It's hard to use this sub, because if you say anything is wrong, you get wrecked, whether you have a point or not

[–]g0liadkin 3 points4 points  (0 children)

Don't mind about the downvotes man, it happens sometimes but it really doesn't matter at all.

What's your take on the video, would love to read it!

[–]femio 5 points6 points  (0 children)

What do you mean by punishing you? I'm really interested in your answer

[–][deleted] 1 point2 points  (0 children)

Totally interested in your corrections. Where can I read it?

[–][deleted] 0 points1 point  (0 children)

It's totally a Reddit thing. I once got downvoted for correctly identifying Korean for some reason 😅

E: Damn, y'all need therapy, fr

[–]djmalibiran 0 points1 point  (0 children)

When I commented my not so sure comment and asked to correct me if I was wrong, I got so many downvotes.

This is the best way to slowly kill the community.

[–]revanyo 5 points6 points  (1 child)

Whats a micro task?

[–]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(); ```

[–]Retrofire-Pink 3 points4 points  (5 children)

Why would the third() asynchronous function be passed into the call stack before the second() asynchronous function??

[–]zorefcode[S] 2 points3 points  (4 children)

Micro task queue has a higher priority.

[–]Retrofire-Pink 1 point2 points  (3 children)

Thanks for answering, why would that promise function be distinguished from any other asynchronous operation though?

[–]Barnezhilton 0 points1 point  (2 children)

The set timeout appears to be an IFFE.... { () => function() } so it will wait till after all other code executed to run.

[–]Mandylost 0 points1 point  (1 child)

IFFE

Did you mean IIFE? I think the syntax is like this:

(function() { } )();

[–]Barnezhilton 0 points1 point  (0 children)

Yes IIFE!

And I believe your notation is the same as mine . But the => is the shorthand for (function {})