A very simple class that you can extends from and add a keyed promise queue to avoid running same job concurently
- 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
Yarn:
yarn add keyed-promise-queue
npm:
npm i keyed-promise-queue
const queue = new KeyedPromiseQueue();
const res = await queue.processKeyed('test', () => any_async_function());
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 //
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.
class InheritedClass extends KeyedPromiseQueue {
}
const queue = new InheritedClass();
const res = await queue.processKeyed('test', () => any_async_function());