Understanding callback on this MDN example
the callback is passed by the async package.
Explanation:
As async parallel function takes array or object (in your example) of asynchronous tasks and these async tasks require a callback which will get called when its execution completes or if there is an error. So parallel function provides these callback functions and will call your callback ( provided as a second parameter to parallel function call) when all of them are called or got an error in any of them.
You can check the detailed explanation from here - https://caolan.github.io/async/v3/docs.html#parallel
Update:
Consider parallel as a wrapper function like:
function parallel(tasks, userCallback) { let tasksDone = []; function callback(err, data){ // this is the callback function you're asking for if(err){ userCallback(err); // calling callback in case of error }else { tasksDone.push(data); if(tasks.length === tasksDone.length){ userCallback(null, tasksDone); // calling callback when all the tasks finished } } } tasks.forEach(task => { task(callback); // calling each task without waiting for previous one to finish })}
Note: This is not a proper implementation of parallel function of async, this is just an example to understand how we can use callback function internally and what is its usecase