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

Behaviour for callers collection implementations.

caller is a process that uses the Poolex.run/3 function and waits for the execution result.

Note that the caller's typespec matches GenServer.from()

Summary

Callbacks

Adds caller to state and returns new 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.

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

Removes caller by pid from state and returns new state.

Removes caller by reference from state and returns new state.

Returns list of callers.

Types

state()

@type state() :: any()

Callbacks

add(state, t)

@callback add(state(), Poolex.Caller.t()) :: state()

Adds caller to state and returns new 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.

pop(state)

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

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

remove_by_pid(state, caller_pid)

@callback remove_by_pid(state(), caller_pid :: pid()) :: state()

Removes caller by pid from state and returns new state.

remove_by_reference(state, reference)

@callback remove_by_reference(state(), reference :: reference()) :: state()

Removes caller by reference from state and returns new state.

to_list(state)

@callback to_list(state()) :: [Poolex.Caller.t()]

Returns list of callers.