-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventLoop.js
More file actions
24 lines (17 loc) · 789 Bytes
/
eventLoop.js
File metadata and controls
24 lines (17 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//event loop
// event loop handles the asynchronous in js.
// its job is to check if the callstack is empty . need to refill from task quene based on priority .
// HIgher prioriy task quene is microtask quene it includes promises.
// the lower priority task quene is macrotask quene it includes setInterval, setTimeout
// when the callstack is empty the eventloop will first take from micro task then will take from macrotask
console.log("start");
setTimeout(()=>{
console.log("setTimeout(macrotask quene)") // (macrotask quene lower priority)
},0)
Promise.resolve().then(()=>console.log("promise(microtask quene)")); // microtask quene (higher priority)
console.log("end");
// the output will be :
// start
// end
// promise(microtask quene)
// setTimeout(macrotask quene)