@jjmschofield/await-queue
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

await-queue

CircleCI Coverage Status Known Vulnerabilities

A simple awaited queue for NodeJs.

Designed to make managing concurrency limiting a breeze using tidy async/await syntax.

Installation

$ npm install @jjmschofield/await-queue

Usage

// Import the module
const { Queue } = require('@jjmschofield/await-queue');

const someQueableThing = async () =>{
    // Create a queue
    const queue = new Queue();
    
    // Await your task
    const result = await queue.add(someAsyncTask, { prop: 'value' });
    
    // Profit
}

Your async task can be any awaitable thing, it should take an object of inputs as it's first parameter eg:

const someAsyncTask = async ({ a, b }) =>{
    return { a, b };
}

As you can imagine, you can add virtually any function in which returns a promise, the world is your oyster!

Config

What is a handy library without some config options? Here are yours:

const { Queue, QUEUE_MODE } = require('<path to file>');

const queue = new Queue({ 
    maxRetry: 3, // Number of times to retry a thing before returning the final error recieved
    mode: QUEUE_MODE.FIFO, // Can be 'FIFO' or 'LIFO'
    concurrency: 1, // How many tasks do you want to run at once?
}); 

Package Sidebar

Install

npm i @jjmschofield/await-queue

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

81.6 kB

Total Files

60

Last publish

Collaborators

  • jjmschofield