Daniel Khan - Everything I thought I knew about the event loop was wrong

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 21

  • @lonewolf2547
    @lonewolf2547 4 роки тому +2

    This was really great. It is so underrated

  • @ashutoshningot4483
    @ashutoshningot4483 4 роки тому

    Thanks DK ,This is what i was waiting for. All the best and thanks for contribution.🙏

  • @arthurfedotiew3609
    @arthurfedotiew3609 2 роки тому +3

    At 20:26, when he shows stdouts, it s actually non-deterministic that setTimeout's callback fires before immediate. One time it can, and other time it can be vice versa, since it depends on OS load, and characteristics. setTimeout with zero is actually will be cast to 4ms under the hood, and event loop can get to the first setImmediate phase faster. Otherwise, it's great presentation nevertheless!!!

    • @yogeshshelke3510
      @yogeshshelke3510 11 місяців тому +1

      it would be deterministic here because calculation of Fibonacci will take some time so by that time setTimeout callback will be added to the timer queue and will execute before check queue callback

  • @lucisetumbrae
    @lucisetumbrae 3 роки тому

    Fantastic talk. Thank you.

  • @sten6160
    @sten6160 4 роки тому +4

    15:04 I think the tick on the diagram is wrong. There should only be one tick after the event loop takes a full trip. Ref: nodejs.dev/learn/understanding-process-nexttick

    • @sten6160
      @sten6160 4 роки тому

      Seems what he really mean is the process.nextTick callback.

    • @amlivinginhell
      @amlivinginhell 4 роки тому

      @@sten6160 what do you mean? it looks like he missed to specify process.nextTick section in eventloop diagram right?

    • @yogeshshelke3510
      @yogeshshelke3510 11 місяців тому

      ​@@amlivinginhell process.nexttick add callback to microtask queue, which is checked in between each phase, that is what it means here in the diagram

  • @madhukardr2029
    @madhukardr2029 4 роки тому

    Awesome explanation of event loop with good diagrams.

  • @luillyfe
    @luillyfe 5 років тому

    what a genius !! Thanks.

  • @movie961
    @movie961 2 роки тому +1

    4:53 my question is what is the meaning "everything in node js is asynchronous except your code

    • @fadelibrahim7663
      @fadelibrahim7663 2 роки тому

      the code thats not async, for example a normal function, function example(a, b){return a+b}

    • @movie961
      @movie961 2 роки тому

      ​@@fadelibrahim7663 But when we create a promise, the promise is asynchronous. so my code is asynchronous
      let myPromise = new Promise(function(resolve, reject) {
      resolve("true");
      });
      await myPromise

    • @fadelibrahim7663
      @fadelibrahim7663 2 роки тому +1

      @@movie961 look I agree what he said causes confusion. And yea a promise is async, the timers are async, network request are async, file system request they are async if you used the async ones, process.nexttick is async, streams are async, (those are the code that's get scheduled/pushed to the process.nextick/microtask/timers/poll/check queues) I think those are the phases of the event loop that he covered there is other but we don't use them, so what he means is everything you write that's not scheduled added to the above queues it is "your code" he is talking about, it is the sync code that gets executed before anything else of the async code.

  • @Mercio2
    @Mercio2 2 роки тому

    nice talk! 👏

  • @deepakdonde9199
    @deepakdonde9199 2 роки тому

    Actual video starts at 11:50

  • @lucaswoods1725
    @lucaswoods1725 3 роки тому

    Woops, wrong Daniel khan

    • @movie961
      @movie961 2 роки тому

      what wrong?

    • @lucaswoods1725
      @lucaswoods1725 2 роки тому

      @@movie961 nothing, I just meant this one ua-cam.com/video/6VoMrvOzYCQ/v-deo.html

  • @hukar075
    @hukar075 4 роки тому +1

    19:25 fibonacci(20) == 6765 :) not 10946 (fibonacci(21) == 10946)