npm install pace-yourself




A priority queue and consumer
Kind: global class
* PriorityQueue
* [new PriorityQueue([priorities])](#new_PriorityQueue_new)
* [.enqueue(entry, [priority])](#PriorityQueue+enqueue) ⇒ promise
* .dequeue() ⇒ function
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [priorities] | array | [1, 2] | An array of priority levels the queue should support from highest to lowest |
Example
``js`
const queue = new PriorityQueue();
Kind: instance method of PriorityQueue
Returns: promise - A promise that resolves with enqueued function
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| entry | function | | The function to enqueue |
| [priority] | number | this.priorities[0] | The priority of the function to enqueue |
Example
`js`
const queue = new PriorityQueue();
queue.enqueue(() => 'ayy', 2);
// → returns a promise that resolves with 'ayy'
Kind: instance method of PriorityQueue
Returns: function - The dequeued function
Example
`js`
const queue = new PriorityQueue();
queue.enqueue(() => 'lmao', 2).then(result => console.log(result));
queue.dequeue()();
// → resolves the promise, logging 'lmao'
Kind: global class
* QueueConsumer
* [new QueueConsumer(queue, [delay])](#new_QueueConsumer_new)
* .start()
* .stop()
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| queue | PriorityQueue | | The queue to consume |
| [delay] | number | 2500 | The interval, in ms, to wait between dequeueing functions |
Example
`js`
const queue = new PriorityQueue();
const consumer = new QueueConsumer(queue, 86400000);
Kind: instance method of QueueConsumer
Kind: instance method of QueueConsumer
`sh`
npm run test
`sh`
npm run coverage
`sh`
npm run lint
`sh`
npm run readme
`sh``
npm run compile
MIT @ Flip