Skip to content

Instantly share code, notes, and snippets.

@bmarini
Created November 16, 2011 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmarini/1370744 to your computer and use it in GitHub Desktop.
Save bmarini/1370744 to your computer and use it in GitHub Desktop.
async callbacks in a loop
app.get '/riders', (req, res) ->
redis.smembers 'riders', (err, replies) ->
results = []
build_json = (rider) ->
redis.hgetall rider, (err, reply) ->
results.push reply
res.json(results, 200) if results.length == replies.length
build_json rider for rider in replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment