API Reference producer_queue v5.0.2

Modules

Implementation details:

iex> alias ProducerQueue.PriorityKeyServer
...> priority_keys = [:h, :l, :empty]
...> high = {3, :queue.from_list([1, 2, 3])}
...> low = {4, :queue.from_list(~w(d e f g)a)}
...> empty = {0, {[], []}}
...> state = {priority_keys, %{h: high, l: low, empty: empty}}
...> {_, [1], state} = PriorityKeyServer.handle_call({:pop, 1}, :_, state)
...> {_, [2, 3], state} = PriorityKeyServer.handle_call({:pop, 2}, :_, state)
...> {_, _, state} = PriorityKeyServer.handle_call({:push, {:h, [4]}}, :_, state)
...> {_, [4], _state} = PriorityKeyServer.handle_call({:pop, 1}, :_, state)

iex> alias ProducerQueue.PriorityKeyServer
...> priority_keys = [:h, :l, :empty]
...> high = {3, :queue.from_list([1, 2, 3])}
...> low = {4, :queue.from_list(~w(d e f g)a)}
...> empty = {0, {[], []}}
...> state = {priority_keys, %{h: high, l: low, empty: empty}}
...> {_, [], state} = PriorityKeyServer.handle_call({:pop, 0}, :_, state)
...> {_, [1, 2, 3, :d, :e, :f, :g], _} = PriorityKeyServer.handle_call({:pop, 10}, :_, state)

iex> alias ProducerQueue.PriorityKeyServer
...> priority_keys = [:h, :l]
...> empty = {0, {[], []}}
...> state = {priority_keys, %{h: empty, l: empty}}
...> {:noreply, state} = PriorityKeyServer.handle_cast({:push, {:_, [:a]}}, state)
...> {_, [:a], _} = PriorityKeyServer.handle_call({:pop, 1}, :_, state)

iex> alias ProducerQueue.PriorityKeyServer
...> {_, {[:a, :b, :c], _}} = PriorityKeyServer.init(priority: [:a, :b, :c])

A simple implementation of a GenStage producer

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