Just 3 useful functions:
- taskList( items, func, callback, opts)
- taskMap( items, func, callback, opts)
- taskChain( items, func, callback, opts)
All of them execute a function func
on an array of elements items
and
call callback(results)
when they finish:
var items = [obj1,obj2,obj3,objn];
function func(obj,done){ //some long async task
//do something on obj
done(null,obj); //when the procedure is completed with no error
//or done(null,obj); //when the procedure is completed with an error
}
function callback(errors,unordered_items){ /* ... */ }
taskList(items,func,callback);
The differences are:
Execute a function on an array of items regardless of
- order of execution
- order of resulting array
- concurrency limit
Execute a function on an array of items regardless of
- order of execution
- concurrency limit
but keeping
- order of resulting array
Execute a function on an array of items; each execution comes exactly after the last one. So use it if you care about concurrency limit and order of execution.