Upload
javascript-meetup-hcmc
View
264
Download
0
Embed Size (px)
DESCRIPTION
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
Citation preview
w/o callback Presented by: Khoa Tran
Jan 7th 2014
Agenda
• Why I don’t like callbacks
• Is there good alternative to write async code?
• Generator
• Get rid of callbacks
Why I don’t like callbacks?
1. Lots of nesting functions
2. Variable scope confusion
3. Handle exceptions everywhere
Writing readable code is hard!!!
Is there good alternative?
• Async
• Fiber
• Promise/Q
• Co
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()
process val1
…
yield val1
next() …
yield val2 process val2
…
val1
val2
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.
Get rid of callbacks
Clone demo source at:
https://github.com/tvkkpt/jsmeetup-demo
What to do next
Join this open-source project:
https://github.com/visionmedia/co
About us
Author: Khoa Tran
Find me at: [email protected]
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
Thank you and HAPPY NEW
YEAR!