That's certainly interesting. Is the point to try to execute the two
requests for data simultaneously? Or just that you need to get two
sets of data and then act on them?
I usually just nest the calls with continuations. However, the Async
package adds some niceties for calling code in parallel or serially
and then calling a continuation. I do find it weird that you're using
a route middleware for loading data, but I can't say that that's
entirely incorrect.
By the way, there's a nicety in CoffeeScript that you can use a fat
arrow (=>) to bind 'this' in a lambda. Instead of:
that = this
return (req, res, next) ->
finished = []
res.data or= {}
keys.forEach (key) ->
that[key] res.data, (k) ->
finished.push k
next() if finished.length == keys.length
you could do:
v
return (req, res, next) =>
finished = []
res.data or= {}
keys.forEach (key) ->
this[key] res.data, (k) ->
finished.push k
next() if finished.length == keys.length