Skip to content

Latest commit

 

History

History
53 lines (42 loc) · 1.68 KB

README.md

File metadata and controls

53 lines (42 loc) · 1.68 KB

keyed-promise-queue

A very simple class that you can extends from and add a keyed promise queue to avoid running same job concurently

Build Status Coverage Status

Features

  • Add a promess to the queue with an unique key
  • if you add another promess with the same queue we will return the first promess
  • TypeScript typings built-in

Usage

Install

Yarn:

yarn add keyed-promise-queue

npm:

npm i keyed-promise-queue

Create Queue

const queue = new KeyedPromiseQueue();
const res = await queue.processKeyed('test', () => any_async_function());

Using Semaphore

const queue = new KeyedPromiseQueue({{ semaphore: 1 }});
const res = await queue.processKeyed('test', () => any_async_function());

passing a value to the property semaphore in the constructor option will ensure that only x task will be running in //

Using Semaphore

const queue = new KeyedPromiseQueue({{ timeout: 1 }});
const res = await queue.processKeyed('test', () => any_async_function());

passing a value to the property timeout in the constructor option will ensure that every new process will wait x milliseconds before starting.

Inherit from the queue class

class InheritedClass extends KeyedPromiseQueue {
}
const queue = new InheritedClass();
const res = await queue.processKeyed('test', () => any_async_function());