# `Shardex.Adapter`
[🔗](https://github.com/epinault/shardex/blob/v0.1.0/lib/shardex/adapter.ex#L1)

Behaviour for pool adapters.

`init/2` runs once per `{shard, role}` pool (at boot and on `add_shard`),
never on the routing path. It returns:

  * `:state` - adapter state passed to `run/2`
  * `:ref` - the value handed to callers (`Shardex.ref/3`)
  * `:child_spec` - how to start the pool (any `Supervisor.child_spec/2`
    input), or `nil` when the pool is managed elsewhere
  * `:meta` - adapter-specific info exposed on `%Shardex.Pool{}`

`run/2` wraps a call in adapter context (e.g. Ecto's `put_dynamic_repo`).
Default: `fun.(ref)`.

Pool process names should be built with `Module.concat([instance, shard, role])`.

# `ctx`

```elixir
@type ctx() :: %{instance: atom(), shard: atom(), role: atom()}
```

# `init_result`

```elixir
@type init_result() :: %{
  :state =&gt; term(),
  :ref =&gt; term(),
  optional(:child_spec) =&gt;
    Supervisor.module_spec() | Supervisor.child_spec() | nil,
  optional(:meta) =&gt; map()
}
```

# `init`

```elixir
@callback init(opts :: keyword(), ctx()) :: {:ok, init_result()} | {:error, term()}
```

# `run`
*optional* 

```elixir
@callback run(state :: term(), (term() -&gt; result)) :: result when result: term()
```

---

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