3.0.0 • Published 1 year ago

@lcrespilho/async-task-queue v3.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

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;
};
3.0.0

1 year ago

2.0.2

2 years ago

2.0.1

2 years ago

1.0.1

2 years ago

1.1.1

2 years ago

1.0.0

2 years ago