meteor and asynchronous done right !
DESCRIPTION
Talk about how FiberJS resolves asynchronous issues within callbacks hellTRANSCRIPT
#4
MeteorAsynchronous done right with Meteor
Agendaintroproblemsolutionoutro
My name is Abderrazak BOUADMA
I’mSoftware Engineer (java)
works at
@mbtdoor linkedIn G+
intro
Meteor is a platform
built on top of NodeJS
to build cutting edge fast
web applications.
created to Get Things Donelocked free approach
scalable to the infinity … and beyondEmbraces Simplicity
created to Get Things Donelocked free approach
scalable to the infinity … and beyondEmbraces Simplicity
created to Get Things Donelocked free approach
scalable to the infinity … and beyondEmbraces Simplicity
created to Get Things Donelocked free approach
scalable to the infinity … and beyondEmbraces Simplicity
but ...
still have a long way to go.
a problem :(
Event Loop
is a programming construct that waits
for and dispatches events
or messages in a program
http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
Synchronous !
process fork
threads
single thread
while(new Date().getTime() < now + 1000) { // do nothing}
all I/O is evented and asynchronous
var fs = require('fs');
fs.readFile( __dirname + '/test.txt', function (err, data) {
if (err) {
throw err;
}
console.log(data.toString());
});
loop{db.connect()
conn.query(“select”)
conn.execute(“insert”)
conn.execute(“delete”)
callback pyramid of
a solution :)
Fibershttps://github.com/laverdet/node-fibers
allows us to write asynchronous
code without callbacks
futures
var fs = require('fs');
fs.readFile( __dirname + '/test.txt', function (err, data) {
if (err) {
throw err;
}
});
console.log(data.toString());
var fs = require('fs');
fs.readFile( __dirname + '/test.txt', function (err, data) {
if (err) {
throw err;
}
});
// console.log(data.toString()); won’t run as the ‘data’
// variable is not accessible at this point.
Solutionvar fs = require('fs');
var d;
fs.readFile( __dirname + '/test.txt', function (err, data) {
if (err) {
throw err;
}
d = data;
});
console.log(d.toString());
Resourceshttp://bjouhier.wordpress.com/2012/03/11/fibers-and-threads-in-node-js-what-for/
http://meteorhacks.com/fibers-eventloop-and-meteor.html
http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
https://github.com/laverdet/node-fibers
Thanks