I am using the async library (https://github.com/caolan/async)
on node trying to execute multiple db queries async with mongoskin (https://github.com/guileen/node-mongoskin)
The problem is when using the map function like so
app.post '/events', (req, res) ->
storage.events.getByUser req.session.authId, (events) ->
async.map events, storage.codes.getCountByEvent, (err, results) ->
res.send results
it is binding @ to the global namespace on the getCountByEvent function, does anybody with experience with the async library able to give me guidance on the best way to fix this?
Here is the sample of the storage.codes implementation
class Codes
constructor: (db) ->
db.bind 'codes',
getCountByEvent: (event, callback) ->
@.find(event: event._id).toArray (err, res) ->
callback res.length
return db.codes
exports.Codes = Codes
calling getCountByEvent outside of the async.map it will work fine
Thanks in advance
You could create a version of
getCountByEventthat’s bound to thestorage.codesobject: