Packages
poolex
0.9.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/behaviour.ex
defmodule Poolex.Workers.Behaviour do
@moduledoc """
Behaviour for worker collection implementations.
"""
@type state() :: any()
@doc "Returns `state` (any data structure) which will be passed as the first argument to all other functions."
@callback init() :: state()
@doc "Same as `init/0` but returns `state` initialized with passed list of workers."
@callback init(list(pid())) :: state()
@doc "Adds worker's pid to `state` and returns new state."
@callback add(state(), Poolex.worker()) :: state()
@doc "Returns `true` if given worker contained in the `state`, `false` otherwise."
@callback member?(state(), Poolex.worker()) :: boolean()
@doc "Removes given worker from `state` and returns new state."
@callback remove(state(), Poolex.worker()) :: state()
@doc "Returns the number of workers in the state."
@callback count(state()) :: non_neg_integer()
@doc "Returns list of workers pids."
@callback to_list(state()) :: list(Poolex.worker())
@doc "Returns `true` if the `state` is empty, `false` otherwise."
@callback empty?(state()) :: boolean()
@doc "Removes one of workers from `state` and returns it as `{caller, state}`. Returns `:empty` if state is empty."
@callback pop(state()) :: {Poolex.worker(), state()} | :empty
end