If you want, for example, the forEach
functionality of async
(https://github.com/caolan/async), you can always look into its' source and reimplement it yourself.
A simplistic implementation could look like this:
function forEach(arr, fun, callback) {
var toDo = arr.length;
var doneCallback = function() {
--toDo;
if(toDo === 0) {
callback();
}
}
for(var i = 0, len = arr.length; i < len; ++i) {
fun(arr[i], doneCallback);
}
}
It assumes the function you want to run takes an array element and a callback. You could modify it to collect results, handle errors, etc. I encourage you to look into async
's source.