Node.js Tutorials - 43 - Microtask Queues

  Рет қаралды 51,419

Codevolution

Codevolution

Күн бұрын

Пікірлер: 75
@AFK_SLAYER
@AFK_SLAYER Жыл бұрын
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-hc4bf
@MathewAlex-hc4bf 4 ай бұрын
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 ?
@hypernova5159
@hypernova5159 27 күн бұрын
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
@dhavalkothari6711
@dhavalkothari6711 27 күн бұрын
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
@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
@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_More
@Sarvesh_More 11 ай бұрын
hey i would really appreciate if you could provide me some reference where i can study about it. This behavior looks confusing.
@privateanon7623
@privateanon7623 11 ай бұрын
@@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_More
@Sarvesh_More 11 ай бұрын
@@privateanon7623 Thank you.
@prasasthaslife6270
@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
@HarshVardhan-tk3ej Жыл бұрын
Core concepts explained with a heart winning simplicity.
@spellsaif
@spellsaif Жыл бұрын
Your teaching style is so so beautiful that I was able to predict the result. Thank you so much :)
@miladhajishafiee8225
@miladhajishafiee8225 2 ай бұрын
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
@olaleyeolabanjo
@olaleyeolabanjo 26 күн бұрын
Very true
@NyanTint
@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
@shorty696820 Жыл бұрын
Your explanation is the clearest one I've ever heard. Thanks a lot!
@chaitanyapatil337
@chaitanyapatil337 4 ай бұрын
Thanks for a crystal clear explanation. i have watched react series too and i learnt a lot as mostly focuses on practical part.
@gregthomas5887
@gregthomas5887 Жыл бұрын
I magically got it right on the first try thanks to your great explanations.
@AswiniduttBevara
@AswiniduttBevara Жыл бұрын
Your teaching style is so so awesome. I'm able to predict the result. Thank you :)😀
@amanpreetsingh2696
@amanpreetsingh2696 3 ай бұрын
Too deep knowledge, that's also for free... thanks man
@mdsafikulislam7430
@mdsafikulislam7430 2 жыл бұрын
Sir! You are great in this field!
@AlbinSabu-y2v
@AlbinSabu-y2v 10 ай бұрын
Simply outstanding🔥. U made it easy to catch those complex concepts 🎉
@abdullah-ayy
@abdullah-ayy Жыл бұрын
I always give your video a like before even watching it.
@innopro22tech
@innopro22tech 2 ай бұрын
i feel so good that i was able to pridict the results
@nischalbista6436
@nischalbista6436 Жыл бұрын
your explanation is soooooo good that I got it right
@nithishnaidu5542
@nithishnaidu5542 7 ай бұрын
11:57 I thought the nested nextTick ("nextTick inside nextTick") will be executed in the next event loop iteration.
@Shorts-zd4hn
@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
@ajilvc5316
@ajilvc5316 7 ай бұрын
Thank you so much for this tutorial. It helped me a lot
@pradneshkhedekar5279
@pradneshkhedekar5279 Жыл бұрын
Really great explanation and on point with visual representation 👍
@sahilmistry2898
@sahilmistry2898 Жыл бұрын
Greate explanation with patience👌👌
@owethuweek6283
@owethuweek6283 Жыл бұрын
Thanks a lot. You have made my day!
@sidhantkumarsingh2
@sidhantkumarsingh2 4 ай бұрын
beautifully explained
@Saqib-w9z
@Saqib-w9z Ай бұрын
Well explained ❤
@amankale4692
@amankale4692 Жыл бұрын
*space bar* 4:06 ~ "That's what she said". *space bar*
@AruljothySundramoorthy
@AruljothySundramoorthy 4 ай бұрын
Awesome , nailed iT 🔥
@MinhLe-ow6op
@MinhLe-ow6op 7 ай бұрын
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
@sanjarcode Жыл бұрын
Thanks a lot, Vishwas
@YakshithKulal-t1o
@YakshithKulal-t1o Жыл бұрын
According to my understanding, the global function will also be removed from the call stack before running any async code
@igetom
@igetom Жыл бұрын
no
@LearnWithJK03
@LearnWithJK03 Жыл бұрын
Just wow concept 🙏🥰
@MathewAlex-hc4bf
@MathewAlex-hc4bf 4 ай бұрын
But the nexttick has priority over the promise ,right . So nexttick should be executed in the promise section before the last promise callback ?
@jivanmainali1742
@jivanmainali1742 11 ай бұрын
How does call stack knows to which queue it should put callbacks to ???
@zallesov
@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
@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
@noname15820 Жыл бұрын
great job! thank you
@chidimmaokafor7173
@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
@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
@mohammedashiq2720 Жыл бұрын
Well explanation
@webstartergurus4463
@webstartergurus4463 8 ай бұрын
Hello sir.. i got the promise.resolve.then consoled first before the process.nexttick console
@alamir411
@alamir411 Ай бұрын
Amazing Thanks.
@rokckerzzzz6080
@rokckerzzzz6080 2 жыл бұрын
Awesome Video...
@pronaypramanick4467
@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'?
@CodeCampTamil
@CodeCampTamil 2 ай бұрын
But for me Promise.resolve executes before process.nextTick, is this a current working pattern?. Because i just have your code
@zallesov
@zallesov Жыл бұрын
So Calling nextTick inside nextTick actually executes the callback in the same cycle and not in the next.
@privateanon7623
@privateanon7623 Жыл бұрын
It goes beyond that. NextTick and Microtask queues are emptied after every event loop action, rather than phase or iteration.
@rustolebayev3248
@rustolebayev3248 4 ай бұрын
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
@kalpeshjadvani7358
@kalpeshjadvani7358 10 ай бұрын
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.
@AlRashidashraf
@AlRashidashraf 2 жыл бұрын
Got right for next tick, but little different for promise.resolve,
@faizanahmed9304
@faizanahmed9304 2 жыл бұрын
Got right man!
@kerimagayev7330
@kerimagayev7330 3 ай бұрын
amazing
@frontend_ko
@frontend_ko Жыл бұрын
thanks teacher 43
@thirunavukarasusaminathan3102
@thirunavukarasusaminathan3102 Жыл бұрын
Yes i got the same results
@iqbalali9796
@iqbalali9796 Жыл бұрын
In my case promise queue running before process.nextTick queue
@andrewshaban2888
@andrewshaban2888 Жыл бұрын
Why did they make it so complex? Why do we need so many queues?
@privateanon7623
@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
@natarajanyuvaraj5265 Жыл бұрын
Got it right
@gobicorner
@gobicorner Жыл бұрын
i got that right
@rishiraj2548
@rishiraj2548 2 жыл бұрын
🙏👍👍
@olaleyeolabanjo
@olaleyeolabanjo 2 ай бұрын
I failed it 😅
@ashokyadavfqplmgxjia4668
@ashokyadavfqplmgxjia4668 9 ай бұрын
sir where is your feet i want touch it for it's clear explaination.............thanks sir.........always respect for great teacher.......
@Pareshbpatel
@Pareshbpatel 11 ай бұрын
{2024-01-30}
@theboyIncomfortzone
@theboyIncomfortzone 8 ай бұрын
စောက်ပေါ 🤗👍👏👏
@igetom
@igetom Жыл бұрын
Good tutorial but, god, your ending of all senteces is so annoying
@mohitpal1505
@mohitpal1505 8 ай бұрын
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
@silentsounds6556
@silentsounds6556 7 ай бұрын
same
Node.js Tutorials - 44 - Timer Queue
10:31
Codevolution
Рет қаралды 31 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Java vs C# in 2025 - Which One Would I Choose?
5:54
Stefan Mischook
Рет қаралды 13 М.
Node.js Tutorial - 42 - Event Loop
14:21
Codevolution
Рет қаралды 131 М.
What are Message Queues? | BullMQ Queues NodeJS
44:12
Piyush Garg
Рет қаралды 42 М.
JavaScript Visualized - Event Loop, Web APIs, (Micro)task Queue
12:35
Learn Why JavaScript Frameworks Love Signals By Implementing Them
20:15
Scaling your Node.js app using the "cluster" module
13:44
Software Developer Diaries
Рет қаралды 51 М.
JavaScript Event Loop: How it Works and Why it Matters in 5 Minutes
7:20
Mastering Memory Management in Node.js: Tips and Tricks for Better Performance
16:06
Software Developer Diaries
Рет қаралды 40 М.
RabbitMQ Crash Course
42:53
Hussein Nasser
Рет қаралды 208 М.
PROOF JavaScript is a Multi-Threaded language
8:21
Beyond Fireship
Рет қаралды 296 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН