meteor and asynchronous done right !

Post on 09-May-2015

587 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Talk about how FiberJS resolves asynchronous issues within callbacks hell

TRANSCRIPT

#4

MeteorAsynchronous done right with Meteor

Agendaintroproblemsolutionoutro

Thanks to

for their support to Meteor Meetup

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

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());

Thanks

top related