async-parallel-impl-question
by upigilam
JavaScript
//Implement async.parallel or some function that takes an array of functions and a callback to be called when all of those functions are done executing. The callback should be a node-style callback,
// tasks can be array of fn or object of fn
// tasks = [add, sub, mult]
// parallel(tasks, [callback])
const add = (a, b) => a + b
const sub = (a, b) => a - b
const mult = (a, b) => a * b
const parallel = (tasks, callback) => {
try {
const result = tasks.map(fn => fn())
} catch (err) {
return callback(null, err)
}
return callback(result)
}