Don't know what you have to apologize for. The switches between the diagram and the code are fantastic and help more. Thank you
@MathewAlex-hc4bf4 ай бұрын
the nexttick has priority over the promise right ? so in the last promise section the next tick should work immediately after the last callback right ?
@hypernova515927 күн бұрын
I thought the same but he explains that control is still in promise queue so it is getting executed first and then it checks the microstask queue and then goes to next tick @@MathewAlex-hc4bf
@dhavalkothari671127 күн бұрын
I think you are the only person having detailed videos on each phase of event loop. Your videos are very very helpful. Thank you very much for sharing knowledge and understanding. Last but not least, I love your videos.
@muhammedsahad1612 Жыл бұрын
The first time I saw the diagram, I skipped the entire tutorial, but after a few months, I started watching it again. The phase and queues in Node JS are now clear to me... thank you so much!
@privateanon7623 Жыл бұрын
The nextTick queue takes precedence over the microtask queue, but the example in (5:50 to 8:35) is only half correct. In fact, if someone runs it as an ESM script (.mjs file or with type="module" in package.json), the output will always be: 2 -> 3 -> 1 That's because instead of executing it synchronously, node schedules it as a microtask callback (like wrapping everything in queueMicroTask(() => { ... }), kind of). So after executing the code, the event loop grabs the next callback in the microtask queue until it becomes empty before checking the nextTick queue. Same thing for the 2nd example. Output for ESM would be: promise 1 promise 2 promise 3 nextTick 1 nextTick 2 nextTick 3 nextTick inside Promise nextTick inside nextTick
@Sarvesh_More11 ай бұрын
hey i would really appreciate if you could provide me some reference where i can study about it. This behavior looks confusing.
@privateanon762311 ай бұрын
@@Sarvesh_More I understand the confusion. The closest thing to a reference that you can get is PR 45093 in the official github repo (/nodejs/node/pull/45093), specifically the review made by devsnek. It's an issue of erroneous documentation in the official docs and unfortunately, the PR addressing it has been stale for more than a year now. But basically, the mental model is the exact same, with the initial code being executed in the microtask queue
@Sarvesh_More11 ай бұрын
@@privateanon7623 Thank you.
@prasasthaslife6270Ай бұрын
This is the best explanation for the event loop. Thank you so much for helping all of us and sharing your in depth knowledge.
@HarshVardhan-tk3ej Жыл бұрын
Core concepts explained with a heart winning simplicity.
@spellsaif Жыл бұрын
Your teaching style is so so beautiful that I was able to predict the result. Thank you so much :)
@miladhajishafiee82252 ай бұрын
The second inference: In the "commonjs" type all callbacks in the nextTick queue are executed before callbacks in the promise queue. In "module" or in TypeScript all callbacks in the promise queue are executed before callbacks in the nextTick queue
@olaleyeolabanjo26 күн бұрын
Very true
@NyanTint Жыл бұрын
You are one of the best teachers I ever met, sir. Everything explained well and short to the point. Got it in one go and I got my confidence boosted!
@shorty696820 Жыл бұрын
Your explanation is the clearest one I've ever heard. Thanks a lot!
@chaitanyapatil3374 ай бұрын
Thanks for a crystal clear explanation. i have watched react series too and i learnt a lot as mostly focuses on practical part.
@gregthomas5887 Жыл бұрын
I magically got it right on the first try thanks to your great explanations.
@AswiniduttBevara Жыл бұрын
Your teaching style is so so awesome. I'm able to predict the result. Thank you :)😀
@amanpreetsingh26963 ай бұрын
Too deep knowledge, that's also for free... thanks man
@mdsafikulislam74302 жыл бұрын
Sir! You are great in this field!
@AlbinSabu-y2v10 ай бұрын
Simply outstanding🔥. U made it easy to catch those complex concepts 🎉
@abdullah-ayy Жыл бұрын
I always give your video a like before even watching it.
@innopro22tech2 ай бұрын
i feel so good that i was able to pridict the results
@nischalbista6436 Жыл бұрын
your explanation is soooooo good that I got it right
@nithishnaidu55427 ай бұрын
11:57 I thought the nested nextTick ("nextTick inside nextTick") will be executed in the next event loop iteration.
@Shorts-zd4hn Жыл бұрын
It's been wonderful sir, and i got it right in the first try and you made it possible for me to guess
@ajilvc53167 ай бұрын
Thank you so much for this tutorial. It helped me a lot
@pradneshkhedekar5279 Жыл бұрын
Really great explanation and on point with visual representation 👍
@sahilmistry2898 Жыл бұрын
Greate explanation with patience👌👌
@owethuweek6283 Жыл бұрын
Thanks a lot. You have made my day!
@sidhantkumarsingh24 ай бұрын
beautifully explained
@Saqib-w9zАй бұрын
Well explained ❤
@amankale4692 Жыл бұрын
*space bar* 4:06 ~ "That's what she said". *space bar*
@AruljothySundramoorthy4 ай бұрын
Awesome , nailed iT 🔥
@MinhLe-ow6op7 ай бұрын
Hi, your explanation is the clearest one I've ever heard. Thank you very much, but can I ask you for this slide for reference?
@sanjarcode Жыл бұрын
Thanks a lot, Vishwas
@YakshithKulal-t1o Жыл бұрын
According to my understanding, the global function will also be removed from the call stack before running any async code
@igetom Жыл бұрын
no
@LearnWithJK03 Жыл бұрын
Just wow concept 🙏🥰
@MathewAlex-hc4bf4 ай бұрын
But the nexttick has priority over the promise ,right . So nexttick should be executed in the promise section before the last promise callback ?
@jivanmainali174211 ай бұрын
How does call stack knows to which queue it should put callbacks to ???
@zallesov Жыл бұрын
Also, I noticed that using Promises puts the execution of the handler to the next cycle. While using regular js callbacks execute right away in for example IO or Timer cycles. Is it fair to say that using callbacks is faster than using Promises? using Promise will add an additional cycle event if it is just Promise.resolve?
@hamza_dev Жыл бұрын
Yes callbacks are a little bit faster but the difference is negligible specially when you consider the elegance and readability promises provide.
@noname15820 Жыл бұрын
great job! thank you
@chidimmaokafor7173 Жыл бұрын
I am a bit confused. I thought the inner CallBacks would join the next iteration. which would mean the sequence would be NextTick1, NextTick2, NextTick3, PromiseResolve1 PromiseResolve2 PromiseResolve3 NextTick inside NextTick, Promise inside Promise
@privateanon7623 Жыл бұрын
That's nextTick/Microtask queues' quirk. The event loop will keep executing all the callbacks of each one until both are empty. You can block your program by abusing this mechanism.
@mohammedashiq2720 Жыл бұрын
Well explanation
@webstartergurus44638 ай бұрын
Hello sir.. i got the promise.resolve.then consoled first before the process.nexttick console
@alamir411Ай бұрын
Amazing Thanks.
@rokckerzzzz60802 жыл бұрын
Awesome Video...
@pronaypramanick4467 Жыл бұрын
Hey, I have a question. Why did you repeatedly use the phrase 'user-written synchronous code' in your explanations? Why do we have to mention 'user written'?
@CodeCampTamil2 ай бұрын
But for me Promise.resolve executes before process.nextTick, is this a current working pattern?. Because i just have your code
@zallesov Жыл бұрын
So Calling nextTick inside nextTick actually executes the callback in the same cycle and not in the next.
@privateanon7623 Жыл бұрын
It goes beyond that. NextTick and Microtask queues are emptied after every event loop action, rather than phase or iteration.
@rustolebayev32484 ай бұрын
promise 1 promise 2 nextTick inside promise promise 3 i thought the order should be like that. because nextTick queue have priority higher than promise queue
@kalpeshjadvani735810 ай бұрын
Promise.resolve().then(() => console.log('start resolved promise')); process.nextTick(() => console.log('start nextTick')); I have run this in my local but bit confusing for me. I am getting [nodemon] restarting due to changes... [nodemon] starting `node justDemo.js` start resolved promise start nextTick [nodemon] clean exit - waiting for changes before restart As you can see I got in same order, not able to understand.
@AlRashidashraf2 жыл бұрын
Got right for next tick, but little different for promise.resolve,
@faizanahmed93042 жыл бұрын
Got right man!
@kerimagayev73303 ай бұрын
amazing
@frontend_ko Жыл бұрын
thanks teacher 43
@thirunavukarasusaminathan3102 Жыл бұрын
Yes i got the same results
@iqbalali9796 Жыл бұрын
In my case promise queue running before process.nextTick queue
@andrewshaban2888 Жыл бұрын
Why did they make it so complex? Why do we need so many queues?
@privateanon7623 Жыл бұрын
The answer is rather complicated and is related to how operating systems handle each type of task, but in essence, each queue is made for some kind of work that has its own quirks. For example, timers are organized in an ordered heap that puts expired timers in the timers queue, while close functions are low priority and only need to be pushed as they come (FIFO).
@natarajanyuvaraj5265 Жыл бұрын
Got it right
@gobicorner Жыл бұрын
i got that right
@rishiraj25482 жыл бұрын
🙏👍👍
@olaleyeolabanjo2 ай бұрын
I failed it 😅
@ashokyadavfqplmgxjia46689 ай бұрын
sir where is your feet i want touch it for it's clear explaination.............thanks sir.........always respect for great teacher.......
@Pareshbpatel11 ай бұрын
{2024-01-30}
@theboyIncomfortzone8 ай бұрын
စောက်ပေါ 🤗👍👏👏
@igetom Жыл бұрын
Good tutorial but, god, your ending of all senteces is so annoying
@mohitpal15058 ай бұрын
Promise.resolve().then(() => console.log("this is Promise 1")); process.nextTick(() => console.log("nextTick 1")); Why output is actually coming : this is Promise 1 nextTick 1