Elixir QLib v0.1.0 QLib.LeasedQueue

LeasedQueue is a simple and leased abstraction around state.

The items stored in a LeasedQueue have a limited lifetime. The LeasedQueue sets a period time or lease time (by default 60 seconds) which is used to automatically remove expired items.

An item expires if its time (processing time) in the queue is greater than the leased time specified by the queue. The processing time is the time when the item was stored in the queue.

A LeasedQueue guarantees that a pop-call never will return an expired item.

Examples

{:ok, q} = LeasedQueue.new LeasedQueue.push(q, 1) LeasedQueue.pop(q) LeasedQueue.size(q) LeasedQueue.clear(q) LeasedQueue.destroy(q)

Summary

Functions

Removes all the items in the LeasedQueue

Destroy the LeasedQueue

Creates a new empty LeasedQueue using the lease value as lease time

Removes and return the first item in the LeasedQueue

Inserts the item in the LeasedQueue

Returns the size of the LeasedQueue

Functions

clear(queue)

Removes all the items in the LeasedQueue.

destroy(queue)

Destroy the LeasedQueue.

new(lease \\ 60000)

Creates a new empty LeasedQueue using the lease value as lease time.

pop(queue, timeout \\ 5000)

Removes and return the first item in the LeasedQueue.

push(queue, item)

Inserts the item in the LeasedQueue.

size(queue, timeout \\ 5000)

Returns the size of the LeasedQueue.