ProducerQueue.Queue (producer_queue v5.0.2) View Source

Start under a supervisor or application:

alais ProducerQueue.Queue

children = [
  {Queue, name: SomeSimpleMod},
  {Queue, name: SomeAdvancedMod, priority: SomeAdvancedMod.priority()},
  # queue consumers here
]

See: pop/2, push/2, push_async/2, and start_link/1 for details

Priority Queues

iex> alias ProducerQueue.Queue
...> {:ok, q} = Queue.start_link(priority: [:high, :medium, :low])
...> :ok = Queue.push(q, medium: [4, 5, 6])
...> :ok = Queue.push_async(q, low: [7, 8, 9])
...> :ok = Queue.push(q, high: [1, 2])
...> :ok = Queue.push_async(q, high: 3)
...> Queue.pop(q, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for GenServer.init/1.

Pop a number of items of the front of a queue (timeout: 10000)

Push a list of items on to the back of a queue (timeout: 10000)

Push a list of items on to the back of a queue (without blocking)

Example: Using a custom queue server implementation:

iex> alias ProducerQueue.Queue
...> {:ok, _pid} = Queue.start_link(module: MyCustomQueueImplementation)

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Callback implementation for GenServer.init/1.

Specs

pop(queue :: pid() | term(), count :: non_neg_integer()) :: list()

Pop a number of items of the front of a queue (timeout: 10000)

Example

iex> alias ProducerQueue.Queue
...> {:ok, q} = Queue.start_link([]); :ok = Queue.push_async(q, [:a, :b])
...> Queue.pop(q, 1)
[:a]

See: Queue for priority queue details

Specs

push(queue :: pid() | term(), item_or_list :: list() | term()) :: :ok

Push a list of items on to the back of a queue (timeout: 10000)

Example

iex> alias ProducerQueue.Queue
...> {:ok, q} = Queue.start_link([])
...> :ok = Queue.push(q, :a); :ok = Queue.push(q, [:b, :c])
...> [:a, :b, :c] = Queue.pop(q, 3)
[:a, :b, :c]

See: Queue for priority queue details

Specs

push_async(queue :: pid() | term(), item_or_list :: list() | term()) :: :ok

Push a list of items on to the back of a queue (without blocking)

Example

iex> alias ProducerQueue.Queue
...> {:ok, q} = Queue.start_link([])
...> :ok = Queue.push_async(q, :a); :ok = Queue.push_async(q, [:b, :c])
...> [:a, :b, :c] = Queue.pop(q, 3)
[:a, :b, :c]

See: Queue for priority queue details

Example: Using a custom queue server implementation:

iex> alias ProducerQueue.Queue
...> {:ok, _pid} = Queue.start_link(module: MyCustomQueueImplementation)