Skip to content

Instantly share code, notes, and snippets.

@jmreidy
Created June 27, 2012 00:13
Show Gist options
  • Save jmreidy/3000395 to your computer and use it in GitHub Desktop.
Save jmreidy/3000395 to your computer and use it in GitHub Desktop.
Callbacks vs Promises
#callbacks
async.parallel([
(done) ->
Post.findAll((err, posts) ->
done(err, posts)
)
(done) ->
Category.findAll((err, docs) ->
done(err, docs)
)
],
(err, results) ->
if err
#do err stuff
[posts, categories] = results
#do stuff
#promises
Q.all([Post.findAll(), Category.findAll()])
.then((results) ->
[posts, categories] = results
#do stuff
).fail((err) ->
#do err stuff
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment