Skip to content

neckaros/keyed-promise-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ebf7e71 · Mar 18, 2019

History

8 Commits
Mar 18, 2019
Mar 18, 2019
Dec 1, 2018
Dec 1, 2018
Dec 1, 2018
Dec 1, 2018
Dec 1, 2018
Dec 1, 2018
Mar 16, 2019
Dec 1, 2018
Mar 16, 2019
Dec 1, 2018
Dec 1, 2018
Dec 1, 2018
Mar 16, 2019

Repository files navigation

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

About

Manage a keyed queue of promises

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published