JSON
require('something');
// 1. try something.js
// 2. try something.json
// 3. try something.node
Addons
> npm i node-gyp -g
> npm install --global --production windows-build-tools
Concurrency Model and Event Loop
Event Model
The Event Loop
Slow I/O Operations
What is I/O Anyway?
Handling Slow I/O
Event Loop
The Event Loop
The entity that handles external events and converts them into callback invocations
The Event Loop
A loop that picks events from the event queue and pushes their callbacks to the call stack
The Call Stack
anonymous()
printDouble(9)
double(9)
add(9, 9)
anonymous()
printDouble(9)
console.log(18)
add(9, 9)
double(9)
Handling Slow Operations
anonymous()
slowAdd(3, 3)
slowAdd(4, 4)
slowAdd(5, 5)
console.log(6)
console.log(8)
console.log(10)
How Callbacks Actually Work
anonymous()
slowAdd(3, 3)
setTimeout()
slowAdd(4, 4)
setTimeout()
console.log(6)
console.log(8)
Timer()
cb1
cb2
cb1
cb2
anonymous()
slowAdd(3, 3)
setTimeout(cb1, d)
Timer
cb1
slowAdd(4, 4)
setTimeout(cb2, d)
Timer
cb2
cb1
cb2
cb1
console.log(6)
cb2
console.log(8)
setImmediate & process.nextTick
anonymous()
slowAdd(3, 3)
setTimeout(cb1, d)
Timer
cb1
cb1
slowAdd(4, 4)
setTimeout(cb2, d)
Timer
cb2
cb2
cb1
console.log(6)
console.log(6)
cb2
Who Named These?
Concurrency Model
By Shuhratbek Mamadaliyev
Concurrency Model
- 973