trying to wrap my head around some basic async programming concepts.
Right now I essentially have two functions, for now lets call them getOne and getAll. getAll essentially loops of a series and makes a call to getOne, then maps it to a hash and sends it back down the chain. Here is basically what I have, in coffeescript:
getOne = (key, callback) ->
try
# find object referenced by key
object = "blah blah"
callback(null, object)
catch(error)
callback(error, null)
getAll = (keys, callback) ->
results = {}
try
count = keys.length
for i, key of keys
count--
getOne key, (err, result) ->
if(err)
# do something
else
results[key] = result
if count is 0
callback "", results
catch
callback error, results
The above code essentially outputs a hash where the keys don't necessarily lineup with the expected data, which is expected the way a for loop is async processed. However, I can't seem to come up with a solution that doesn't block the loop and cause everything to be processed in a series instead of maintaining parallel processing.
What am I missing?