#29 NODE JS Event Loop in Practice | Fundamentals of NODE JS | A Complete NODE JS Course

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 41

  • @hardikarora1521
    @hardikarora1521 Год назад +8

    haven't seen someone teaching so clearly in my entire clg life

  • @jaya_surya
    @jaya_surya Месяц назад +3

    Thanks

  • @qatadd8313
    @qatadd8313 Год назад +23

    I Have Never Find Someone Explaining The Node.js Like You , You Are Amazing For Sure..!

    • @ashimbera23
      @ashimbera23 Год назад

      I second it

    • @mohamedibrahemsaad573
      @mohamedibrahemsaad573 10 месяцев назад

      I third it

    • @vivekkoul4428
      @vivekkoul4428 8 месяцев назад

      I 4th it

    • @HaamroNotes
      @HaamroNotes 2 месяца назад

      *******Please help me guys to clear this doubt Did any of you face this issue *******
      How come readFile is executed before setImmediate even though the file is very large about 90mb?
      const fs=require('fs')
      //Top level code gets executed first in the main thread
      console.log("Program has started")
      //Timer callback stored in the first phase of event loop
      setTimeout(()=>{
      console.log("Timer callback executed")
      },0)
      //After 1s pushed in the main thread if it is empty
      //If the timer has 1000ms as time then in the event just the timer starts and it moves to the next phase of the event loop and again when it comes to the same phase if timer has complete
      //IO third phase might take time callback function willbe pushed to the main thread only when io task is completed
      fs.readFile("../PipeMethod/large-file.txt","utf-8",()=>{
      console.log("Async callback read file executed")
      })
      //stored in the callback queue in the third phase of the event loop
      setImmediate(()=>{
      console.log("setImmediate callback executed")
      })
      //According to node js documentation setImmediate should expire before any other timer but that is not always the case.
      //Top level code gets executed first in the main thread
      console.log("Program has completed")
      /Output
      Program has started
      Program has completed
      Timer callback executed
      Async callback read file executed
      setImmediate callback executed
      How come readFile is executed before setImmediate even though the file is very large about 90mb?

  • @Ansha-xq1uy
    @Ansha-xq1uy 11 месяцев назад +4

    This guy is amazing ! Never keeps a black hole In any of his videos !

  • @karmpatel-p2z
    @karmpatel-p2z Год назад +4

    wow ! what the lecture it is? the most beautiful thing is the educator does not have any hurry and he explain each and every point very calmly .

  • @yashkankal9529
    @yashkankal9529 6 месяцев назад +2

    Your node.js series is awesome sir. The way u explain is the best among all other RUclips channels 👏🏻🙇🏻‍♂️

  • @dreamvallyhasan4807
    @dreamvallyhasan4807 Месяц назад +1

    What a explain .................Superve

  • @PritiSahoo-fu4mt
    @PritiSahoo-fu4mt 3 месяца назад

    I must say, this is one of the most exceptional videos I've come across online. Your dedication and effort are truly commendable, sir. Thank you for sharing your expertise with us!

  • @Manishdasss
    @Manishdasss Год назад +3

    Wow such a nice explanation

  • @rakeshrout2719
    @rakeshrout2719 2 месяца назад

    Very informative..... got the event loop the way i want

  • @mukeshmahadev7419
    @mukeshmahadev7419 Год назад +1

    Very clear Explanation, thank you.
    Started binge watching this playlist. It's awesome.
    Your articulation and presentation is too good.

  • @pirobanda9150
    @pirobanda9150 4 месяца назад

    these lectures are really helpful sir,thank you!!

  • @muhammadayyaz1197
    @muhammadayyaz1197 5 месяцев назад

    Your series is outstanding. The way you're explaining how things works behind the scene is awesone 🥰 Love it 🥰

  • @asqdekoietozsigarapusha8484
    @asqdekoietozsigarapusha8484 9 месяцев назад +1

    the best explanation ever!

  • @yogyapundir9642
    @yogyapundir9642 2 года назад +2

    You are champ❣️
    Keep it up bro
    Lots of love from delhi/ncr

  • @吳冠賢-t1v
    @吳冠賢-t1v Год назад

    thanks you sir. You teached very clearly and explain so well.

  • @eduardcojocaru5674
    @eduardcojocaru5674 Год назад

    Very well explained, amazing job! Thank you!

  • @abdulrehman-dl8bd
    @abdulrehman-dl8bd Год назад

    great efforts

  • @LasithaYapabandara
    @LasithaYapabandara Год назад

    Thank you very much for the great explanation

  • @devkumar9889
    @devkumar9889 11 месяцев назад

    So much clarity

  • @heartmusic4398
    @heartmusic4398 9 месяцев назад

    Great !

  • @sairam9638
    @sairam9638 7 месяцев назад

    amazing man!!

  • @hassannouri9796
    @hassannouri9796 7 месяцев назад

    ❤❤❤

  • @chaitanyakarthik3536
    @chaitanyakarthik3536 Год назад

    amazing explanation I mean it !!

  • @ashishyadav-tu2pd
    @ashishyadav-tu2pd 9 месяцев назад +2

    Guru ji, app insaan nhi, "Maha purush" h.....

  • @youssefhammam6902
    @youssefhammam6902 Год назад +1

    thanks for the explanation sir but I have a question
    setTimeout(() => {
    setTimeout(() => {
    console.log('nested settimeout finishes');
    }, 0);
    setImmediate(() => console.log('Immediate 1 finishes'));
    }, 0);
    why setImmediate() here gets called before the inner setTimeout()
    shouldn't the inner setTimeout gets executed before the setImmediate here
    because the event loop starts in the timer phase and executes the outer setTimeout then adds the inner setTimeout to the timer phase queue which the event loop is still currently at and then add the setImmediate callback to the third phase
    now the event loop is still at the timer phase why the inner setTimeout callback is not executed first before the setImmediate callback that is in the third phase

    • @vatsavag5061
      @vatsavag5061 Год назад

      I thought of the same. Let me know if you find the answer :)

    • @vatsavag5061
      @vatsavag5061 Год назад

      Hey, I think in the explanined example while dealing with file it is in 2nd phase(IO Tasks and Polling). Eventhough there are inner things going on, the next will be execute i.e, "Set immediate callback." So that's why set Immediate gets executed immediately. But if it contains any time consuming tasks then in the next control Timers and Set-immediate will be executed. I think....

    • @h2k196
      @h2k196 Год назад +1

      as outer setTimeout() callback is executed it is in the first phase, callback have setTimeout() and and setImmediate which will run asynchornouly , as both expired immediately inner setTimeout()'s callback will store in first phase callback and setImmediate()'s callback will be stored in 3rd phase callback queue.
      Now as the callback of outer setTimeout get executed now event loop will move to the 2nd phase and then 3rd phase where it get callback function waiting for execution... and executed first even before the inner setTimeout() callback

    • @vivekkoul4428
      @vivekkoul4428 8 месяцев назад

      As explained by a person above, as soon as the event loop pushes the callback to the main thread, it moves to the next phase as it doesn't know what are the things in the callback. That job is of the main thread to decide which code goes where. So event loop reaches the 2nd phase and setTimer has to wait

  • @AnimeBoyYT
    @AnimeBoyYT 9 месяцев назад

    22:02 that means event loop phases can have nested event loop as well if our program needs if code have call backs in call backs. i think thats the reason call back hell is bad. am i right?

    • @procademy
      @procademy  9 месяцев назад +1

      That's absolutely right

    • @AnimeBoyYT
      @AnimeBoyYT 9 месяцев назад

      @@procademy thanks man 🫡

  • @bolooemmanuel6651
    @bolooemmanuel6651 8 месяцев назад

    You should be a lecturer by default. I didn't watch it twice before understanding the concept.

  • @vivekkoul4428
    @vivekkoul4428 8 месяцев назад

    I have a doubt at 23:31. When the event loop is in 2nd phase and reaches setImmediate, instantly its callback will be pushed to the callback queue. At this loint event loop doesnt know whats ahead of it. It doesnt know process.nextTick is the next line. Why event loop doesnt execute 3rd phase callback even though event loop is in 3rd phase and the stack is empty ?