ets_deque v0.2.0 EtsDeque.Server View Source
EtsDeque.Server is a GenServer wrapper around an EtsDeque. It provides safe access to a deque from multiple processes, ensuring each operation on the deque is atomic.
Example
iex> {:ok, pid} = EtsDeque.Server.start_link(size: 3)
iex> :ok = EtsDeque.Server.push_head(pid, :moe)
iex> :ok = EtsDeque.Server.push_tail(pid, :larry)
iex> :ok = EtsDeque.Server.push_tail(pid, :curly)
iex> :error = EtsDeque.Server.push_tail(pid, :shemp) ## deque is full
iex> {:ok, :curly} = EtsDeque.Server.pop_tail(pid)
iex> :ok = EtsDeque.Server.push_tail(pid, :shemp)
iex> EtsDeque.Server.execute(pid, fn deque -> Enum.to_list(deque) end)
[:moe, :larry, :shemp]
Link to this section Summary
Functions
Returns the item at the given index, where index 0
is the head.
Returns :error
if index is out of bounds.
Returns a specification to start this module under a supervisor.
Returns the deque. Ensuring that no other process mutates
the deque after it is returned is the caller's responsibility.
See execute/3
for a safer alternative.
Executes fun.(deque)
, ensuring no other process is accessing the
deque at the same time. Returns the result.
Returns the number of items in the given deque.
Returns the item at the head of the queue, or :error
if the queue
is empty.
Returns the item at the tail of the queue, or :error
if the queue
is empty.
Removes the item at the head of the queue, returning it along with the
updated deque.
Returns :error
if queue is empty.
Removes the item at the tail of the queue, returning it along with the
updated deque.
Returns :error
if queue is empty.
Adds an item onto the head of the queue. Returns the updated deque,
or :error
if the queue is full.
Adds an item onto the tail of the queue. Returns the updated deque,
or :error
if the queue is full.
Replaces the item at the given index, returning the updated deque.
Returns :error
if index is out of bounds.
Returns the maximum capacity of the given deque.
Link to this section Functions
at(pid, index, timeout \\ 5000)
View Sourceat(pid(), non_neg_integer(), timeout()) :: {:ok, any()} | :error
Returns the item at the given index, where index 0
is the head.
Returns :error
if index is out of bounds.
Returns a specification to start this module under a supervisor.
See Supervisor
.
deque(pid, timeout \\ 5000)
View Sourcedeque(pid(), timeout()) :: EtsDeque.t()
Returns the deque. Ensuring that no other process mutates
the deque after it is returned is the caller's responsibility.
See execute/3
for a safer alternative.
execute(pid, fun, timeout \\ 5000)
View Sourceexecute(pid(), (EtsDeque.t() -> any()), timeout()) :: any()
Executes fun.(deque)
, ensuring no other process is accessing the
deque at the same time. Returns the result.
length(pid, timeout \\ 5000)
View Sourcelength(pid(), timeout()) :: non_neg_integer()
Returns the number of items in the given deque.
Returns the item at the head of the queue, or :error
if the queue
is empty.
Returns the item at the tail of the queue, or :error
if the queue
is empty.
Removes the item at the head of the queue, returning it along with the
updated deque.
Returns :error
if queue is empty.
Removes the item at the tail of the queue, returning it along with the
updated deque.
Returns :error
if queue is empty.
Adds an item onto the head of the queue. Returns the updated deque,
or :error
if the queue is full.
Adds an item onto the tail of the queue. Returns the updated deque,
or :error
if the queue is full.
replace_at(pid, index, item, timeout \\ 5000)
View Sourcereplace_at(pid(), non_neg_integer(), any(), timeout()) :: :ok | :error
Replaces the item at the given index, returning the updated deque.
Returns :error
if index is out of bounds.
size(pid, timeout \\ 5000)
View Sourcesize(pid(), timeout()) :: non_neg_integer() | :infinity
Returns the maximum capacity of the given deque.