Packages
poolex
0.10.0
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.0
1.5.0-rc.0
1.4.2
1.4.1
1.4.0
1.3.0
1.2.1
1.2.0
1.1.0
1.0.0
1.0.0-rc.0
0.10.0
0.9.0
0.9.0-rc.2
0.9.0-rc.1
0.9.0-rc.0
0.8.0
0.8.0-rc.1
0.8.0-rc.0
0.7.6
0.7.5
0.7.4
retired
0.7.3
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.0
0.3.1
retired
0.3.0
retired
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
The library for managing pools of workers.
Current section
Files
Jump to
Current section
Files
lib/poolex/workers/impl/erlang_queue.ex
defmodule Poolex.Workers.Impl.ErlangQueue do
@moduledoc """
Simple workers queue (FIFO) implementation based on Erlang `:queue`
"""
@behaviour Poolex.Workers.Behaviour
@impl true
def init do
:queue.new()
end
@impl true
def init(workers) do
:queue.from_list(workers)
end
@impl true
def add(state, worker) do
:queue.in(worker, state)
end
@impl true
def member?(state, worker) do
:queue.member(worker, state)
end
@impl true
def remove(state, worker) do
:queue.filter(fn element -> element != worker end, state)
end
@impl true
def count(state) do
:queue.len(state)
end
@impl true
def to_list(state) do
:queue.to_list(state)
end
@impl true
def empty?(state) do
:queue.is_empty(state)
end
@impl true
def pop(state) do
case :queue.out(state) do
{{:value, worker}, new_state} -> {worker, new_state}
{:empty, _state} -> :empty
end
end
end