You can find us at:
http://www.meetup.com/JavaScript-Ho-Chi-Minh-City/
https://www.facebook.com/JavaScriptHCMC?ref=hlhttps://plus.google.com/communities/116105314977285194967
2. Agenda
•
Why I don’t like callbacks
•
Is there good alternative to write async code?
•
Generator
•
Get rid of callbacks
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. Is there good alternative?
•
Async
•
Fiber
•
Promise/Q
•
Co
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. 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. Get rid of callbacks
Clone demo source at:
https://github.com/tvkkpt/jsmeetup-demo
8. What to do next
Join this open-source project:
https://github.com/visionmedia/co
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