simple-timed-queue
v1.0.8
Published
Queue data structure with expiration
Downloads
18
Maintainers
Readme
simple-timed-queue
Queue data structure with expiration
Syntax
> var q = new TimedQueue(ttl, delta, disableEvents);
> q.enqueue(10 /* any variable/object */);
> q.dequeue();
10
deque can return timeleft of stored object:
> q.dequeue(true);
[10, 200 /* timeleft */ ]
Usage
> var q = new TimedQueue(100); // entries ttl
> q.enqueue('text1');
> q.dequeue();
// test1
> q.enqueue('text2');
...
// 0.1 second here
...
> q.dequeue();
undefined
Queue will emit 'expire' event for item:
q.on('expired', function(data){
console.log('expired:', data);
});
This can be disabled with disableEvents flag:
var q = new TimedQueue(100, null, true);