Created
October 28, 2014 16:18
-
-
Save Kikobeats/bf0ee77573798628d7d7 to your computer and use it in GitHub Desktop.
async wit coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# same code, with async | |
async = require 'async' | |
# all requests will be run in parallel | |
async.parallel [ | |
(cb) -> $.get '/user/:id', cb | |
(cb) -> $.get '/country/:id', cb | |
(cb) -> $.get '/orders/:userId', cb | |
(cb) -> $.get '/relatedProducts/:userId', cb | |
], (err, results) -> | |
if err? | |
# deal with the error | |
else | |
[user, country, orders, relatedProducts] = results | |
# do something with the data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment