# `Spectre.GAM.GovernedAct.DispatchState`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/gam/governed_act/dispatch_state.ex#L1)

Compact lifecycle index for executor-mediated Acts.

Pending dispatches remain a `MapSet` because expiry, authority changes and
reconciliation scan that small hot set repeatedly. Terminal dispatches share
one mutually-exclusive index: an Act either consumed one Attempt or was
cancelled. The durable Attempt and cancellation event remain in the ledger;
this module only reads and updates their disposable projection indexes.

# `cancellation`

```elixir
@type cancellation() :: %{
  cause_ref: String.t(),
  reason:
    :mandate_revoked
    | :mandate_restricted
    | :mandate_expired
    | :disputed_evidence,
  cancelled_at: non_neg_integer()
}
```

# `terminal`

```elixir
@type terminal() :: {:attempt, String.t()} | {:cancelled, cancellation()}
```

# `attempt_ref`

```elixir
@spec attempt_ref(Spectre.GAM.GovernedAct.State.t(), String.t()) :: String.t() | nil
```

Returns the Attempt bound to an Act, or `nil` before/without execution.

# `attempted?`

```elixir
@spec attempted?(Spectre.GAM.GovernedAct.State.t(), String.t()) :: boolean()
```

Returns whether an Act has consumed an Attempt.

# `cancellation`

```elixir
@spec cancellation(Spectre.GAM.GovernedAct.State.t(), String.t()) ::
  cancellation() | nil
```

Returns the cancellation bound to an Act, or `nil` when not cancelled.

# `cancellations`

```elixir
@spec cancellations(Spectre.GAM.GovernedAct.State.t()) :: Enumerable.t()
```

Returns terminal cancellation entries without materializing another index.

# `cancelled?`

```elixir
@spec cancelled?(Spectre.GAM.GovernedAct.State.t(), String.t()) :: boolean()
```

Returns whether an Act's dispatch was cancelled.

# `expired`

```elixir
@spec expired(Spectre.GAM.GovernedAct.State.t(), integer()) ::
  {:ok, [{Spectre.GAM.Act.t(), Spectre.GAM.Mandate.t()}]} | {:error, term()}
```

Returns pending executor Acts whose pinned Mandate has expired.

# `pending`

```elixir
@spec pending(Spectre.GAM.GovernedAct.State.t()) ::
  {:ok, [{Spectre.GAM.Act.t(), Spectre.GAM.Mandate.t()}]} | {:error, term()}
```

Returns the validated Act and pinned Mandate behind each pending dispatch.

# `pending?`

```elixir
@spec pending?(Spectre.GAM.GovernedAct.State.t(), String.t()) :: boolean()
```

Returns whether an Act is waiting at the executor boundary.

# `pending_refs`

```elixir
@spec pending_refs(Spectre.GAM.GovernedAct.State.t()) :: MapSet.t(String.t())
```

Returns the hot set of Acts still eligible to consume a Grant.

# `terminal`

```elixir
@spec terminal(Spectre.GAM.GovernedAct.State.t(), String.t()) :: terminal() | nil
```

Returns the terminal dispatch state for an Act, if one exists.

---

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