RINSE
REPEAT
The Node.js event loop and how it works.
Vitor Fernandes
https://github.com/vmlf01/nodejs-rinse-repeat
TopTal Developer @ KWAN
github.com/vmlf01
Summary
-
the motive behind node.js
-
node architecture
-
the event loop
The Motive
Behind
Node.js
Created 2009 by Ryan Dahl
why?
because I/O is slow
Latency numbers every programmer should know
so the idea is:
I/O needs to be done differently
node.js uses an
instead of blocking
event loop
on the cpu
for events
Node
Architecture
Title Text
Subtitle
Title Text
Subtitle
event driven
Title Text
Subtitle
i/o
Title Text
Subtitle
server side js env
Title Text
Subtitle
based on v8
The
Event
Loop
Philip Roberts: What the heck is the event loop anyway?
must see
Call Stack
callback queue
the human node simulator
callback queue
event loop
v8 engine
worker thread
client app
client app
worker thread
client app
The V8 engine has a
Call Stack
and a
Heap*
* it's got memory
everything else
is provided by the host,
be it the
browser
or
Node.js
so
Node.js
is essentialy a
runtime environment
CODE
SAMPLES
create an index.js file with:
console.log('Hello World');
and run it with:
$ node index.js
node will execute the script
inside index.js and exit
that's because
there was nothing else to do!
change index.js to:
setTimeout(function () {
console.log('Hello World');
}, 5000);
and run it again:
$ node index.js
now the application will only
terminate after the
setTimeout
callback is executed
don't block,
collaborate
you have a lot of nanoseconds
at your disposal
thank you!
RINSE
REPEAT
Node.js - Rinse Repeat
By Vitor Fernandes
Node.js - Rinse Repeat
Briefly describe the Node.js event loop and how it works.
- 910