@lcrespilho/async-task-queue
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Async-Task-Queue

Simple Async Task Queue

Task queue with concurrency control.

Useful for rate-limiting async (or sync) operations.

Install

npm install @lcrespilho/async-task-queue

Usage

import { taskQueue } from '@lcrespilho/async-task-queue';

const TaskQueue = taskQueue(process.env.CONCURRENCY || 2);

(async () => {
  const t1 = TaskQueue.push(done => {
    // do sync work...
    done(/*promise return value*/); // notifies that the task is completed
  });

  const t2 = TaskQueue.push(async done => {
    // do sync/async work...
    done(/*promise return value*/); // notifies that the task is completed
  });

  const t3 = TaskQueue.push(async done => {
    // do sync/async work...
    done(/*promise return value*/); // notifies that the task is completed
  });

  await Promise.all([t1, t2, t3]);

  // all tasks completed
})();

API/types

export declare const taskQueue: (concurrency?: string | number, logOnEmpty?: boolean) => {
    push: (task: (done: (result?: any) => void) => void) => Promise<unknown>;
    tasks: () => number;
};

/@lcrespilho/async-task-queue/

    Package Sidebar

    Install

    npm i @lcrespilho/async-task-queue

    Weekly Downloads

    0

    Version

    3.0.0

    License

    Apache-2.0

    Unpacked Size

    15.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • lcrespilho