LimitedQueue (limited_queue v0.1.2) View Source
An elixir wrapper for erlang's :queue
, with a constant-time size/1
and a maximum capacity.
When items pushed on to the LimitedQueue
put it over its maximum capacity,
it will drop events according to its drop_strategy/0
.
Link to this section Summary
Types
The drop_strategy/0
determines how the queue handles dropping events when overloaded.
The opaque internal state of the LimitedQueue
.
Functions
Push multiple values to the back of the LimitedQueue
.
The maximum capacity of the LimitedQueue
.
Filters the queue, i.e. returns only those elements for which fun returns a truthy value.
Create a new LimitedQueue
with the given maximum capacity.
Remove and return a value from the front of the LimitedQueue
.
If the LimitedQueue
is empty, {:error, :empty} will be returned.
Push a value to the back of the LimitedQueue
.
Invokes queue.fold
but using the call signatures of the standard Elixir reduce() function.
The current number of values stored in the LimitedQueue
.
Remove and return multiple values from the front of the LimitedQueue
.
If the LimitedQueue
runs out of values, fewer values than the requested amount will be returned.
The contents of the LimitedQueue
as a list.
Link to this section Types
Specs
drop_strategy() :: :drop_newest | :drop_oldest
The drop_strategy/0
determines how the queue handles dropping events when overloaded.
:drop_newest
(default) drops incoming events and is the most efficient
because it will avoid touching the state when the queue is overloaded.
:drop_oldest
drops the oldest events from the queue,
which may be better behavior where newer events are more relevant to process than older ones.
Specs
t(value)
The opaque internal state of the LimitedQueue
.
Link to this section Functions
Specs
append(t(value), [value]) :: {t(value), dropped :: non_neg_integer()} when value: any()
Push multiple values to the back of the LimitedQueue
.
Returns the number of values that were dropped if the LimitedQueue
reaches its capacity.
Specs
capacity(t(value)) :: non_neg_integer() when value: any()
The maximum capacity of the LimitedQueue
.
Specs
Filters the queue, i.e. returns only those elements for which fun returns a truthy value.
Specs
new(capacity :: pos_integer(), drop_strategy()) :: t(value) when value: any()
Create a new LimitedQueue
with the given maximum capacity.
The drop_strategy
determines how the queue handles dropping events when overloaded.
See drop_strategy/0
for more information.
Specs
Remove and return a value from the front of the LimitedQueue
.
If the LimitedQueue
is empty, {:error, :empty} will be returned.
Specs
Push a value to the back of the LimitedQueue
.
If the LimitedQueue
is full, it will drop an event according to the LimitedQueue
's drop_strategy/0
.
Specs
Invokes queue.fold
but using the call signatures of the standard Elixir reduce() function.
Specs
size(t(value)) :: non_neg_integer() when value: any()
The current number of values stored in the LimitedQueue
.
Specs
split(t(value), amount :: non_neg_integer()) :: {t(value), [value]} when value: any()
Remove and return multiple values from the front of the LimitedQueue
.
If the LimitedQueue
runs out of values, fewer values than the requested amount will be returned.
Specs
The contents of the LimitedQueue
as a list.