Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

keyed-promise-queue

neckaros6MIT2.0.1TypeScript support: included

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

readme

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());