Module emmap_queue
The FIFO queue can be used as a persistent container of messages with constant time push and pop operations.Authors: Serge Aleynikov.
Description
Persistent FIFO queue The FIFO queue can be used as a persistent container of messages with constant time push and pop operations. Additionally, this module provides a gen_server API, which wraps the queue for use in multi-process applications. The queue is stored in a memory-mapped file, and it automatically grows if the messages are not dequeued from the queue. See test cases at the end of this module for sample use cases.Function Index
close/1 | Close a previously open queue. |
dequeue/1 | Dequeue a message from the queue. |
enqueue/2 | Enqueue a message to the queue. |
handle_call/3 | |
handle_cast/2 | |
handle_info/2 | |
info/1 | Return queue info as a map. |
init/1 | |
inspect/1 | Peek a message from the queue without dequeuing it. |
is_empty/1 | Returns true if the queue is empty. |
length/1 | Get queue length. |
open/3 | Open a memory mapped queue. |
peek/1 | Peek the next term from the queue without popping it. |
pop/1 | Pop a term from the queue. |
pop_and_purge/1 | Pop a term from the queue and reclaim queue's memory if the queue is empty. |
purge_queue/1 | Purge queue. |
push/2 | Push a term to the queue. |
start_link/4 | Start a queue process. |
terminate/2 | |
try_dequeue/2 | Dequeue a message from the queue. |
try_pop/2 | Evaluate the Fun function on the next term in the queue. |
try_pop_and_purge/2 | Evaluate the Fun function on the next term in the queue. |
Function Details
close/1
close(Mem) -> any()
Close a previously open queue.
dequeue/1
dequeue(Name) -> any()
Dequeue a message from the queue
enqueue/2
enqueue(Name, Term) -> any()
Enqueue a message to the queue
handle_call/3
handle_call(X1, From, State) -> any()
handle_cast/2
handle_cast(Msg, State) -> any()
handle_info/2
handle_info(X1, State) -> any()
info/1
info(Name::atom()) -> map()
Return queue info as a map
init/1
init(X1) -> any()
inspect/1
inspect(Name) -> any()
Peek a message from the queue without dequeuing it
is_empty/1
is_empty(Mem) -> any()
Returns true
if the queue is empty.
length/1
length(Mem) -> any()
Get queue length. This function has a linear-time complexity.
open/3
open(Filename, Size, Opts) -> any()
Open a memory mapped queue.
peek/1
peek(Mem) -> any()
Peek the next term from the queue without popping it. This function has a constant-time complexity.
pop/1
pop(Mem) -> any()
Pop a term from the queue. This function has a constant-time complexity.
pop_and_purge/1
pop_and_purge(Mem) -> any()
Pop a term from the queue and reclaim queue's memory if the queue is empty. This function has a constant-time complexity.
purge_queue/1
purge_queue(Mem) -> any()
Purge queue. It is a constant time operation.
push/2
push(Mem, Term) -> any()
Push a term to the queue. This function has a constant-time complexity.
start_link/4
start_link(Name, Filename, SegmSize, Opts) -> any()
Start a queue process.
Name
- name of the registered process.
Filename
- name of the memory mapped file.
SegmSize
- size of the memory mapped segment (can be 0 for an existing file).
Opts
- see emmap:open_options()
.
terminate/2
terminate(Reason, State) -> any()
try_dequeue/2
try_dequeue(Name, Fun) -> any()
Dequeue a message from the queue.
The function returns Res
where Res
is the result of evaluating
the Fun
with the poped element from the queue. If the Fun
throws an
exception, the exception if propagated to the caller.
try_pop/2
try_pop(Mem, Fun) -> any()
Evaluate the Fun
function on the next term in the queue.
If the function doesn't raise an exception, pop the term from the queue, otherwise
leave the queue unmodified. This function has a constant-time complexity. It returns
the result of evaluating Fun
.
try_pop_and_purge/2
try_pop_and_purge(Mem, Fun) -> any()
Evaluate the Fun
function on the next term in the queue.
If the function doesn't raise an exception, pop the term from the queue, otherwise
leave the queue unmodified. This function has a constant-time complexity. It returns
the result of evaluating Fun
.