@robinlemon/priority-concurrency-queue
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    Priority Concurrency Queue

    A fast promise queue with priority and concurrency options.

    NPM Package Build Status Coverage Status TypeCov Codechecks

    Installation

    This is a Node.js module available through the npm registry.

    Before installing, download and install Node.js. Node.js 0.10 or higher is required.

    Installation is done using the npm install command:

    $ npm install @robinlemon/priority-concurrency-queue

    Usage

    Sorted highest priority first, then by time added for those of the same priority.

    Short Example:

    import { AsyncQueue, IQueueItem } from '@robinlemon/priority-concurrency-queue';
     
    await (new AsyncQueue({
        Concurrency: 10
    }).Add({
        Task: async () => {};
        Priority1;
    }).Start());
     
    console.log('Tasks Complete!');

    Using AutoStart:

    import { AsyncQueue, IQueueItem } from '@robinlemon/priority-concurrency-queue';
     
    new AsyncQueue({
        Concurrency: 10,
        AutoStart: true,
    }).Add({
        Task: async () => {};
        Priority1;
    });

    Long Example:

    import { AsyncQueue, IQueueItem } from '@robinlemon/priority-concurrency-queue';
     
    const Concurrency = 10;
    const Queue = new AsyncQueue({ Concurrency });
    const Item: IQueueItem = {
        Task: async () => {};
        Priority1;
    };
     
    Queue.Add(Item);
    console.log(Queue.Tasks); // 1
    console.log(Queue.isRunning); // false
    Queue.Start(); // start the queue
    console.log(Queue.isRunning); // true
    await Queue.Start(); // wait until complete
    console.log(Queue.Tasks); // 0
    console.log(Queue.isRunning); // false
     
    /**
     *  Since the concurrency is 10,
     *  only 10 tasks will be processed
     *  and the rest will be idle.
     */
    for(let i = 0; i < 100; i++) Queue.Add(Item);
    Queue.Start();
    Queue.Stop();
     
    console.log('Tasks Complete!');
     
    Queue.Clear(true); // Wait for tasks to finish
     
    // The above is the same as:
    Queue.Clear()
    await Queue.Start();
     
    Queue.Add(Item);
    console.log(Queue.Tasks); // 1
    Queue.ClearPriority(1);
    console.log(Queue.Tasks); // 0

    Tests

    To run the test suite, first install the dependencies, then run npm test:

    $ npm install
    $ npm test

    License

    MIT

    Install

    npm i @robinlemon/priority-concurrency-queue

    DownloadsWeekly Downloads

    0

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    20.8 kB

    Total Files

    9

    Last publish

    Collaborators

    • robinlemon