0.9.3 • Published 5 years ago
timeout-promise-queue v0.9.3
timeout-promise-queue
Promise queue with timeouts and promise cleanup after expiration.
Motivation
Reduce threads associated with forked processes by throttling the creating of processes.
Installation
timeout-promise-queue can be installed using npm:
npm install timeout-promise-queueInterface
PromiseQueue(Number maxConcurrent): QueueQueue#add(Function promseGenerator, [Number timeout, [rejection]]): Promise- calls function to generate a promise to add to the queue- `promiseGenerator(EventEmitter cancel): Promise - generate a promise to add to the queue
- if
timeoutis defined,promseGeneratoris called with an EventEmitter which will get a'timeout'event iftimeoutis exceeded. Ifrejectionis not defined, timeouts callreject(Error('timeout of ' + timeout + ' exceeded'))Ifrejectionis defined, it generates the timeout error.rejectionmust be one of:- if
rejectionis function, timouts callreject(rejection()). - otherwise timouts call
reject(rejection).
- if
Queue#size(): Number- returns number of pending promises
Use
const Queue = require('timeout-promise-queue').PromiseQueue(25) // allow 25 concurrent promises
Promise.all([
Queue.add(cancel => cancellable(cancel)),
Queue.add(cancel => cancellable(cancel)),
Queue.add(cancel => cancellable(cancel))...,
]).then(l => {console.log('done') })