Sounds like you want your mediaHandler
function to return an iterator function:
mediaHandler = (folder, callback) ->
(entry) ->
# Do things with folder, callback, and entry.
# folder and callback are available through the closure,
# entry is supplied by forEach.
and then:
async.forEach dbReply, mediaHandler(event.folder, callback), (error) -> ...
Your entry
argument is supplied by forEach
when it calls the iterator but the other two arguments are (presumably) available when you're calling async.forEach
so you're trying to curry a three argument mediaHandler
to get a one argument function that forEach
can deal with; there are other ways to do that in (Coffee|Java)Script but doing it by hand with a closure is probably the simplest.