Nifty Pony Merchandise

    @ntlab/work

    1.0.2 • Public • Published

    Nodejs queue and promise based work queue

    Queue Processing (queue.js)

    Provide a queue mechanism.

    const { Queue } = require('@ntlab/work');
    
    const queues = ['One', 'Two', 'Three'];
    const q = new Queue(queues, seq => {
        console.log(seq);
        q.next();
    });

    Promise Based Work Queue (work.js)

    Provide promise queue mechanism for easy chaining. It accepts a function as its worker. Its also accepts an array with signature of [function, function] which the first element would be the worker and the second would be a state function and must be evaluated to true for worker to be executed.

    const { Work } = require('@ntlab/work');
    Work.works([
        [w => new Promise((resolve, reject) => {
            console.log('First work');
            resolve(false);
        })],
        [w => new Promise((resolve, reject) => {
            console.log('This will be skipped');
            resolve();
        }), w => w.getRes(0)],
        [w => new Promise((resolve, reject) => {
            console.log('It\'s done');
            resolve();
        })],
    ]);

    Install

    npm i @ntlab/work

    DownloadsWeekly Downloads

    69

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    12.9 kB

    Total Files

    6

    Last publish

    Collaborators

    • tohenk