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

Behaviour for worker collection implementations.

# `state`

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

# `add`

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

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

# `count`

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

Returns the number of workers in the 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.

# `init`

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

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

# `member?`

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

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

# `pop`

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

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

Removes given worker from `state` and returns new state.

# `to_list`

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

Returns list of workers pids.

---

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