Get objects only after timeout, sorted by timeout (longest expiration first).
npm install @aetherwave/timed-queue
let queue = new TimedQueue();
queue.enqueue(999, 'Hello World');
console.log(queue.dequeue()); // -> null
setTimeout(function () {
console.log(queue.dequeue()); // -> Hello World
}, 1000);
Enqueues object with timeout
- If there is one or more item with timeout lower than the current timestamp, this object gets dequeued
- Else
null
is going to be returned
Returns length of the queue
Run tests
$ npm test