meteor and asynchronous done right !

39
#4

Upload: abderrazak-bouadma

Post on 09-May-2015

587 views

Category:

Technology


1 download

DESCRIPTION

Talk about how FiberJS resolves asynchronous issues within callbacks hell

TRANSCRIPT

Page 1: Meteor and asynchronous done right !

#4

Page 2: Meteor and asynchronous done right !

MeteorAsynchronous done right with Meteor

Page 3: Meteor and asynchronous done right !

Agendaintroproblemsolutionoutro

Page 5: Meteor and asynchronous done right !

Thanks to

for their support to Meteor Meetup

Page 6: Meteor and asynchronous done right !

intro

Page 7: Meteor and asynchronous done right !

Meteor is a platform

built on top of NodeJS

to build cutting edge fast

web applications.

Page 8: Meteor and asynchronous done right !

created to Get Things Donelocked free approach

scalable to the infinity … and beyondEmbraces Simplicity

Page 9: Meteor and asynchronous done right !

created to Get Things Donelocked free approach

scalable to the infinity … and beyondEmbraces Simplicity

Page 10: Meteor and asynchronous done right !

created to Get Things Donelocked free approach

scalable to the infinity … and beyondEmbraces Simplicity

Page 11: Meteor and asynchronous done right !

created to Get Things Donelocked free approach

scalable to the infinity … and beyondEmbraces Simplicity

Page 12: Meteor and asynchronous done right !
Page 13: Meteor and asynchronous done right !

but ...

Page 14: Meteor and asynchronous done right !

still have a long way to go.

Page 15: Meteor and asynchronous done right !

a problem :(

Page 16: Meteor and asynchronous done right !

Event Loop

is a programming construct that waits

for and dispatches events

or messages in a program

Page 18: Meteor and asynchronous done right !

Synchronous !

Page 19: Meteor and asynchronous done right !

process fork

Page 20: Meteor and asynchronous done right !

threads

Page 21: Meteor and asynchronous done right !

single thread

Page 22: Meteor and asynchronous done right !

while(new Date().getTime() < now + 1000) { // do nothing}

Page 23: Meteor and asynchronous done right !

all I/O is evented and asynchronous

Page 24: Meteor and asynchronous done right !

var fs = require('fs');

fs.readFile( __dirname + '/test.txt', function (err, data) {

if (err) {

throw err;

}

console.log(data.toString());

});

Page 25: Meteor and asynchronous done right !
Page 26: Meteor and asynchronous done right !

loop{db.connect()

conn.query(“select”)

conn.execute(“insert”)

conn.execute(“delete”)

Page 27: Meteor and asynchronous done right !

callback pyramid of

Page 28: Meteor and asynchronous done right !

a solution :)

Page 29: Meteor and asynchronous done right !

Fibershttps://github.com/laverdet/node-fibers

Page 30: Meteor and asynchronous done right !

allows us to write asynchronous

code without callbacks

Page 31: Meteor and asynchronous done right !

futures

Page 32: Meteor and asynchronous done right !
Page 33: Meteor and asynchronous done right !
Page 34: Meteor and asynchronous done right !

var fs = require('fs');

fs.readFile( __dirname + '/test.txt', function (err, data) {

if (err) {

throw err;

}

});

console.log(data.toString());

Page 35: Meteor and asynchronous done right !

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.

Page 36: Meteor and asynchronous done right !

Solutionvar fs = require('fs');

var d;

fs.readFile( __dirname + '/test.txt', function (err, data) {

if (err) {

throw err;

}

d = data;

});

console.log(d.toString());

Page 37: Meteor and asynchronous done right !
Page 39: Meteor and asynchronous done right !

Thanks