Queutils.BlockingQueue (queutils v1.2.1) View Source

A queue with a fixed length that blocks on Queutils.BlockingQueue.push/2 if the queue is full.

Usage

Add it to your application supervisor's start/2 function, like this:

def start(_type, _args) do
  children = [
    ...
    {Queutils.BlockingQueue, name: MessageQueue, max_length: 10_000},
    ...
  ]

  opts = [strategy: :one_for_one, name: MyApplication.Supervisor]
  Supervisor.start_link(children, opts)
end

Then you can push and pop from the queue like this:

:ok = Queutils.Blockingqueue.push(MessageQueue, :my_message)
[:my_message] = Queutils.Blockingqueue.pop(MessageQueue, 1)

Use with Queutils.BlockingQueueProducer for more fun, or use Queutils.BlockingProducer for the effect of both.

Options

  • :name - the ID of the queue. This will be the first argument to the push/2 function. Default is BlockingQueue.
  • :max_length - The maximum number of messages that this process will store until it starts blocking. Default is 1,000.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for GenServer.init/1.

Get the current length of the queue.

Pop an item off of the queue. Never blocks, and returns a list. The returned list will be empty if the queue is empty.

Get the count of elements that have been popped from a queue over the queue's lifetime.

Push an item onto the queue. This function will block if the queue is full, and unblock once it's not.

Get the count of elements that have been pushed to a queue over the queue's lifetime.

Start a blocking queue process.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Callback implementation for GenServer.init/1.

Specs

length(term()) :: non_neg_integer()

Get the current length of the queue.

Specs

pop(term(), non_neg_integer()) :: list()

Pop an item off of the queue. Never blocks, and returns a list. The returned list will be empty if the queue is empty.

Specs

popped_count(any()) :: integer()

Get the count of elements that have been popped from a queue over the queue's lifetime.

Specs

push(any(), any()) :: :ok

Push an item onto the queue. This function will block if the queue is full, and unblock once it's not.

Specs

pushed_count(any()) :: integer()

Get the count of elements that have been pushed to a queue over the queue's lifetime.

Start a blocking queue process.

Options

  • :name - the ID of the queue. This will be the first argument to the push/2 function. Default is BlockingQueue.
  • :max_length - The maximum number of messages that this process will store until it starts blocking. Default is 1,000.