# `SnakeBridge.Examples`
[🔗](https://github.com/nshkrdotcom/snakebridge/blob/v0.16.0/lib/snakebridge/examples.ex#L1)

Helpers for SnakeBridge example projects.

Provides failure tracking to hard-fail on unexpected errors in demo scripts,
and telemetry-based dispatch monitoring to deterministically wait for pool
dispatch events instead of using `Process.sleep`.

# `assert_no_failures!`

```elixir
@spec assert_no_failures!() :: :ok
```

Raises if any failures were recorded in the current process.

# `assert_script_ok`

```elixir
@spec assert_script_ok(term()) :: :ok
```

Raises if `result` is an `{:error, reason}` tuple.

# `attach_dispatch_monitor`

```elixir
@spec attach_dispatch_monitor(String.t() | nil) :: String.t()
```

Attaches a telemetry handler that forwards `[:snakepit, :pool, :call, :dispatched]`
events to the calling process as `{:call_dispatched, metadata}` messages.

Returns the handler ID, which should be passed to `detach_dispatch_monitor/1`
when monitoring is no longer needed.

# `await_dispatch`

```elixir
@spec await_dispatch(keyword()) :: map() | nil
```

Waits for a `{:call_dispatched, metadata}` message from an attached dispatch monitor.

## Options

  * `:timeout` - maximum wait time in milliseconds (default: `2_000`)
  * `:command` - if set, only matches dispatches for the given command

Returns the dispatch metadata map, or `nil` on timeout.

# `detach_dispatch_monitor`

```elixir
@spec detach_dispatch_monitor(String.t()) :: :ok | {:error, :not_found}
```

Detaches a previously attached dispatch monitor by handler ID.

# `failure_count`

```elixir
@spec failure_count() :: non_neg_integer()
```

Returns the current per-process failure count.

# `record_failure`

```elixir
@spec record_failure() :: :ok
```

Increments the per-process failure counter by one.

# `reset_failures`

```elixir
@spec reset_failures() :: :ok
```

Resets the per-process failure counter to zero.

---

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