BlockingQueue
BlockingQueue is a simple queue implemented as a GenServer. It has a fixed maximum length.
The queue is designed to decouple but limit the latency of a producer and
consumer. When pushing to a full queue the push
operation blocks
preventing the producer from making progress until the consumer catches up.
Likewise, when calling pop
on an empty queue the call blocks until there
is work to do.
Examples
{:ok, pid} = BlockingQueue.start_link(5)
BlockingQueue.push(pid, "Hi")
BlockingQueue.pop(pid) # should return "Hi"
{:ok, pid} = BlockingQueue.start_link(:infinity)
BlockingQueue.push(pid, "Hi")
BlockingQueue.pop(pid) # should return "Hi"
Summary
Functions
Pops the least recently pushed item from the queue. Blocks if the queue is empty until an item is available
Returns a Stream where each element comes from the BlockingQueue
Pushes a new item into the queue. Blocks if the queue is full
Pushes all items in a stream into the blocking queue. Blocks as necessary
Start a queue process with GenServer.start_link/3
Types
Functions
Specs
pop(pid) :: any
Pops the least recently pushed item from the queue. Blocks if the queue is empty until an item is available.
pid
is the process ID of the BlockingQueue server.
Specs
pop_stream(pid) :: Enumerable.t
Returns a Stream where each element comes from the BlockingQueue.
pid
is the process ID of the BlockingQueue server.
Specs
push(pid, any) :: nil
Pushes a new item into the queue. Blocks if the queue is full.
pid
is the process ID of the BlockingQueue server.
item
is the value to be pushed into the queue. This can be anything.
Specs
push_stream(Enumerable.t, pid) :: nil
Pushes all items in a stream into the blocking queue. Blocks as necessary.
stream
is the the stream of values to push into the queue.
pid
is the process ID of the BlockingQueue server.