Qler
Excruciatingly simple synchronous queuing for node, with concurrency support. It provides similar functionality to p-queue
, with the ability to lock concurrency based on a key.
Used in production at https://wellpaid.io.
Installation
npm install qler## or yarn add qler
API
queue(fn, key)
- queue a promise that returns a promise. Will never run two fns with the same key.cancel()
- will cancel all remaining queue items and reject any remaining queue promises.wait()
- wait for all previously queued promises to complete. Returns a promise.
Usage
Basic
Execute two functions in sequence, without blocking main thread.
; const myQueue = ; myQueue // Wait for 2 seconds ; myQueue // Wait for 2 seconds ;
With concurrency
; const myQueue = ; myQueue // Wait for 2 seconds ; myQueue // Wait for 2 seconds ; myQueue // Wait for 2 seconds ;
With keyed concurrency
Keyed concurrency allows you to limit concurrency to certain function calls. If two or more queued function calls share the same key, they won't be run concurrently.
; const myQueue = ; myQueue // Wait for 2 seconds and key on 'foo' ; myQueue // Wait for 2 seconds and key on 'foo' ; myQueue // Wait for 2 seconds and key on 'bar' ;
License
MIT © Chris Villa