# `Hassock.Connection.Backoff`
[🔗](https://github.com/bbangert/hassock/blob/v0.3.0/lib/hassock/connection/backoff.ex#L1)

Reconnect delays: exponential backoff with "equal jitter".

Attempt `n` (1-based) waits a random time between half and all of
`min(max, initial * 2^(n - 1))`, so a fleet of clients that lost Home
Assistant at the same moment doesn't reconnect in lockstep.

# `delay`

```elixir
@spec delay(pos_integer(), pos_integer(), pos_integer(), (-&gt; float())) ::
  non_neg_integer()
```

Delay in milliseconds before reconnect attempt `attempt`.

`rand` returns a float in `[0, 1)`; pass a fixed function for
deterministic results.

---

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