Nearly Pure Mustard

    cargo-p

    1.0.4 • Public • Published

    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([{item:563, ...}, {item:75, ...}, ...])
    batchThisJob(43);
    // jobHandler([{item:43}]) // (after 200 ms)

    Keywords

    none

    Install

    npm i cargo-p

    DownloadsWeekly Downloads

    6

    Version

    1.0.4

    License

    ISC

    Last publish

    Collaborators

    • flamescape