Meteor and asynchronous done right !

1,019 views

Published on

Talk about how FiberJS resolves asynchronous issues within callbacks hell

Published in: Technology, Business
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,019
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
6
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Meteor and asynchronous done right !

  1. 1. #4
  2. 2. Meteor Asynchronous done right with Meteor
  3. 3. Agenda intro problem solution outro
  4. 4. My name is Abderrazak BOUADMA I’m Software Engineer (java) works at @mbtdoor linkedIn G+
  5. 5. Thanks to for their support to Meteor Meetup
  6. 6. intro
  7. 7. Meteor is a platform built on top of NodeJS to build cutting edge fast web applications.
  8. 8. created to Get Things Done locked free approach scalable to the infinity … and beyond Embraces Simplicity
  9. 9. created to Get Things Done locked free approach scalable to the infinity … and beyond Embraces Simplicity
  10. 10. created to Get Things Done locked free approach scalable to the infinity … and beyond Embraces Simplicity
  11. 11. created to Get Things Done locked free approach scalable to the infinity … and beyond Embraces Simplicity
  12. 12. but ...
  13. 13. still have a long way to go.
  14. 14. a problem :(
  15. 15. Event Loop is a programming construct that waits for and dispatches events or messages in a program
  16. 16. http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
  17. 17. Synchronous !
  18. 18. process fork
  19. 19. threads
  20. 20. single thread
  21. 21. while(new Date().getTime() < now + 1000) { // do nothing }
  22. 22. all I/O is evented and asynchronous
  23. 23. var fs = require('fs'); fs.readFile( __dirname + '/test.txt', function (err, data) { if (err) { throw err; } console.log(data.toString()); });
  24. 24. db.connect() conn.query (“select”) loop { conn.execute(“insert”) conn.execute(“delete”)
  25. 25. callback pyramid of
  26. 26. a solution :)
  27. 27. Fibers https://github.com/laverdet/node-fibers
  28. 28. allows us to write asynchronous code without callbacks
  29. 29. futures
  30. 30. var fs = require('fs'); fs.readFile( __dirname + '/test.txt', function (err, data) { if (err) { throw err; } }); console.log(data.toString());
  31. 31. 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.
  32. 32. Solution var fs = require('fs'); var d; fs.readFile( __dirname + '/test.txt', function (err, data) { if (err) { throw err; } d = data; }); console.log(d.toString());
  33. 33. Resources http://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
  34. 34. Thanks

×