-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-loop.js
28 lines (21 loc) · 843 Bytes
/
event-loop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const pendingTimers = [];
const pendingOSTasks = [];
const pendingOperations = [];
function shouldContinue() {
// Check One: Any pending setTimeout, setInterval or setImmediate?
// Check Two: Any pending OS tasks?
// Check Three: Any pending long running operations?
return pendingTimers.length || pendingOSTasks.length || pendingOperations.length
}
while (shouldContinue()) {
// 1) Node looks at pendingTimers and sees if any functions are ready to been called
// 2) Node looks at pendingOSTasks and pendingOperations
// 3) Pause execution. Continue when...
// - a new pendingOSTask is done
// - a new pendingOperation is done
// - a timer is about to complete
// ( async )
// 4) Look at pendingTimers. Call any setImmediate
// 5) Handle any 'close' events
}
// exit back to terminal