cargo-p
v1.0.4
Published
Usage:
Downloads
2
Readme
Usage:
function jobHandler(jobs){
// in this example, jobs is an array of size 1-3
jobs.forEach(function(job){
// job {
// item: XXX,
// resolve: function,
// reject: function,
// promise: Promise
// }
if (job.item > 10) {
job.resolve('this number is greater than 10');
}
// use job.reject() to fail a job
// any jobs not resolved after any returned promises have resolved, will automatically be rejected
});
}
var batchThisJob = cargo(jobHandler, {size: 3, delay: 200});
batchThisJob(563);
batchThisJob(75);
batchThisJob(2);
// jobHandler([...])
batchThisJob(43);
// jobHandler([...]) // (after 200 ms)