# `Lockstep.Agent`
[🔗](https://github.com/b-erdem/lockstep/blob/v0.1.0/lib/lockstep/agent.ex#L1)

Controller-aware `Agent` -- mirrors the OTP `Agent` API but every
`get`/`update`/`cast`/`get_and_update` is a `Lockstep.GenServer.call`
(or `cast`) and therefore a sync point.

Without this wrapper, `Agent.get/3-4` etc. go through vanilla
`:gen_server.call`, bypassing Lockstep's controller. That hides
any race between an `Agent.get` (when the user does work
*outside* the agent based on the value, then calls back in) and
a concurrent `Agent.update`.

A typical example: an LRU cache that does `:ets.lookup` directly
*then* calls `Agent.get(...)` -- a delete in between corrupts the
LRU's TTL table. Lockstep can find that race only if both the ETS
calls AND the Agent calls are sync points.

# `cast`

Fire-and-forget update.

# `cast`

# `get`

Apply `fun` to the agent's state and return the result.

# `get`

Apply `module.fun([state | args])` and return the result.

# `get_and_update`

Atomically get and update via `fun.(state) -> {result, new_state}`.

# `get_and_update`

# `start`

Unlinked variant of `start_link/1`.

# `start`

# `start`

# `start`

# `start_link`

Start an agent linked to the calling process. `fun` is invoked
to produce the initial state.

# `start_link`

Start an agent with options (`name:` for atom registration).

# `start_link`

Start an agent invoking `apply(module, fun, args)` to produce
initial state.

# `start_link`

# `stop`

Stop the agent.

# `update`

Update the state via `fun.(state)`.

# `update`

Update via `module.fun([state | args])`.

---

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