Nodejs wo callback[Khoa Tran]

581 views
430 views

Published on

You can find us at:
http://www.meetup.com/JavaScript-Ho-Chi-Minh-City/
https://www.facebook.com/JavaScriptHCMC?ref=hl https://plus.google.com/communities/116105314977285194967

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

  • Be the first to like this

No Downloads
Views
Total views
581
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Nodejs wo callback[Khoa Tran]

  1. 1. w/o callback Presented by: Khoa Tran Jan 7th 2014
  2. 2. Agenda • Why I don’t like callbacks • Is there good alternative to write async code? • Generator • Get rid of callbacks
  3. 3. Why I don’t like callbacks? 1. Lots of nesting functions 2. Variable scope confusion 3. Handle exceptions everywhere Writing readable code is hard!!!
  4. 4. Is there good alternative? • Async • Fiber • Promise/Q • Co
  5. 5. Generator • “In computer science, a generator is a special routine that can be used to control the iteration behaviour of a loop” - From wikipedia Executor Generator … next() … val1 process val1 yield val1 next() process val2 … … val2 yield val2
  6. 6. Generator in node.js • Only supported in version 0.11.x and above. For now, you have to build and install node.js from Github. • In addition, execute code with --harmony flag.
  7. 7. Get rid of callbacks Clone demo source at: https://github.com/tvkkpt/jsmeetup-demo
  8. 8. What to do next Join this open-source project: https://github.com/visionmedia/co
  9. 9. About us Author: Khoa Tran Find me at: tvkkpt@gmail.com Presentation made for JavaScript HCMC Meetup You can find us at: http://www.meetup.com/JavaScript-Ho-Chi-Minh-City/ https://www.facebook.com/JavaScriptHCMC?ref=hl https://plus.google.com/communities/116105314977285194967
  10. 10. Thank you and HAPPY NEW YEAR!

×