I'm not familiar with the library you're using, but it looks like
async.parallel executes functions you provide to it in parallel, and then saves the results of those parallel function calls in a results object.
In this particular case, you provide it two functions to call in parallel:
genre and
genre_books. When those functions have performed their calculations,
async.parallel still has to perform some logic to put the results in the object. It does this by passing a callback function to the functions you want to perform in parallel. You call the callback function on the results, so
async.parallel can perform the final steps.
After the callback has been executed, the
async.parallel passes the object containing the results that were passed to the callbacks to the function at the bottom, where you can perform your final logic on the results.
So, why don't the functions
genre and
genre_books just return their results, instead of passing them to the callback? This is just a different style of programming, called
continuation-passing style.