View Source Poolex.Workers.Behaviour behaviour (poolex v1.1.0)

Behaviour for worker collection implementations.

Summary

Callbacks

Adds worker's pid to state and returns new state.

Returns the number of workers in the state.

Returns true if the state is empty, false otherwise.

Returns state (any data structure) which will be passed as the first argument to all other functions.

Same as init/0 but returns state initialized with passed list of workers.

Returns true if given worker contained in the state, false otherwise.

Removes one of workers from state and returns it as {caller, state}. Returns :empty if state is empty.

Removes given worker from state and returns new state.

Returns list of workers pids.

Types

state()

@type state() :: any()

Callbacks

add(state, worker)

@callback add(state(), Poolex.worker()) :: state()

Adds worker's pid to state and returns new state.

count(state)

@callback count(state()) :: non_neg_integer()

Returns the number of workers in the state.

empty?(state)

@callback empty?(state()) :: boolean()

Returns true if the state is empty, false otherwise.

init()

@callback init() :: state()

Returns state (any data structure) which will be passed as the first argument to all other functions.

init(list)

@callback init([pid()]) :: state()

Same as init/0 but returns state initialized with passed list of workers.

member?(state, worker)

@callback member?(state(), Poolex.worker()) :: boolean()

Returns true if given worker contained in the state, false otherwise.

pop(state)

@callback pop(state()) :: {Poolex.worker(), state()} | :empty

Removes one of workers from state and returns it as {caller, state}. Returns :empty if state is empty.

remove(state, worker)

@callback remove(state(), Poolex.worker()) :: state()

Removes given worker from state and returns new state.

to_list(state)

@callback to_list(state()) :: [Poolex.worker()]

Returns list of workers pids.