Philip Roberts Help I'm stuck in an event loop

Bili Bili · 33K views · 2016 · 20:14

Open on YouTube

Web developmentPython, Ruby & scripting languagestalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering or asking about setTimeout, closures in loops and non-blocking behaviour, since it shows how the event loop orders callbacks.

Recommended by 1 people across 1 different months, 2016 to 2019.

What it is

A conference talk by Philip Roberts (from a 2014 Scotland JS event) that explains how the JavaScript runtime works: the call stack, Web APIs, the callback queue and the event loop. It uses live visualisations to show how setTimeout and asynchronous callbacks are scheduled.

What people said

Recommends Adi Prasetyo · 2016-03 · Stack Overflow · on “How to identify error [cdep] in AngularJS”

Refer to the official doc: This error occurs when the $injector tries to get a service that depends on itself , either directly or indirectly. Q: from left to right or right to left? A: See the arrow, it's clearly from right to left, and that is also how identify that. Let me give an example when you hit the unpr [LINK] , and yell like so: Unknown provider: loggerProvider <- logger <- loc That indicates your loc things is depen on logger, so To fix that, make sure the dependency is defined and spelled correctly . Thanks to Callum Linington [LINK] For future reference on javascript stack, you can watch video [this video] by Philip Roberts on Scotland Js 9-10 May 2014

Cites Byeongin Yoon · 2018-09 · Stack Overflow · on “How setTimeout() works in nodejs”

I watched a [this video] about javascript in web browswer. They told about WebAPI when explaining how setTimeout() works. In the case of node.js, I think node.js have no WebAPI. How does setTimeout() works in NodeJS?

Cites Alex_B · 2019-01 · Stack Overflow · on “Unexpected behavior: Javascript, setTimeout(), and IIFE”

Javascript, Event loop, setTimeout, IIFE, closure Based on references below, my understanding of the following code is: setTimeout() is non-blocking and handled by the Browser Web APIs, which put the callbacks on the callback queue when the timer is done. Then the event loop waits for the call stack to be free to run each callback in turn. setTimeout closure closes over the anonymous IIFE and has the correct value of index for each iteration. for(var i = 0; i < 3; i++){ (function(index){ setTimeout(function(){ console.log(index); }, 5000); })(i); console.log("loop="+i); } /*Output in console is loop=0 loop=1 loop=2 //after 5 seconds 0 1 2 */ I'm looking for an explanation of what's happening