-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventLoop.js
More file actions
48 lines (32 loc) · 825 Bytes
/
eventLoop.js
File metadata and controls
48 lines (32 loc) · 825 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Event loop Logic:
*
* When the call stack gets empty:
*
* While the queue is not empty:
* event = dequeue an event
* if there is a callback:
* call the event's callback
*/
const fs = require('fs');
//2.
let bar;
const printNextTick = () => console.log('bar', bar);
const someAsyncApiCall = (cb) => process.nextTick(cb);
//1.
const immediately = () => console.log('This is immediately');
const printHello = () => console.log('Hello');
const blockFor500ms = () => {};
const useImportedTweets = (error, data) => {
const tweets = JSON.parse(data)
console.log(tweets.tweet);
};
//execute context
setTimeout(printHello, 0);
fs.readFile('./tweets.json', useImportedTweets);
blockFor500ms();
console.log('Me first');
setImmediate(immediately);
//2.
someAsyncApiCall(printNextTick);
bar = 1;