# `Poolex.Callers.Behaviour`
[🔗](https://github.com/general-CbIC/poolex/blob/main/lib/poolex/callers/behaviour.ex#L1)

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()`**

# `state`

```elixir
@type state() :: any()
```

# `add`

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

Adds caller to `state` and returns new state.

# `empty?`

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

Returns `true` if the `state` is empty, `false` otherwise.

# `init`

```elixir
@callback init() :: state()
```

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

# `pop`

```elixir
@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`

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

Removes caller by pid from `state` and returns new state.

# `remove_by_reference`

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

Removes caller by reference from `state` and returns new state.

# `to_list`

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

Returns list of callers.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
