# `Macaw.Live.Cell.Backoff`
[🔗](https://github.com/dcoai/macaw_live/blob/v0.1.0/lib/macaw/live/cell/backoff.ex#L1)

The restart schedule of a contained cell, a pure value (spec/02 §5). Copied from
visualize's cell restart in `Visualize.Board.Server` (100 ms doubling to 10 s, reset after
30 s alive) and adapted: the schedule is a value the page holds, and the delay a timer on
the page's clock (spec/01 §7), so a test steps it with the manual clock.

A cell that dies is started again after `delay_ms`: 100 ms, doubled at each restart in a
row up to 10 s, and back to 100 ms when the cell had run 30 s or more before it died.
There is no cap on restarts: a component that dies on every input is retried every 10 s
for as long as its page lives.

    iex> backoff = Macaw.Live.Cell.Backoff.new()
    iex> {100, backoff} = Macaw.Live.Cell.Backoff.crashed(backoff, 5)
    iex> {200, backoff} = Macaw.Live.Cell.Backoff.crashed(backoff, 5)
    iex> {delay, _backoff} = Macaw.Live.Cell.Backoff.crashed(backoff, 30_000)
    iex> delay
    100

# `t`

```elixir
@type t() :: %Macaw.Live.Cell.Backoff{next: pos_integer()}
```

The schedule: the delay the next crash in a row waits.

# `crashed`

```elixir
@spec crashed(t(), integer()) :: {pos_integer(), t()}
```

A crash of a cell that had lived `alive_ms`: `{delay_ms, backoff}`, the delay before it
starts again and the schedule after it. A cell that lived 30 s or more starts the
schedule over at 100 ms.

# `new`

```elixir
@spec new() :: t()
```

A fresh schedule: the first crash waits 100 ms.

---

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