Hassock.Connection.Backoff (hassock v0.3.0)

Copy Markdown View Source

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.

Summary

Functions

Delay in milliseconds before reconnect attempt attempt.

Functions

delay(attempt, initial, max, rand \\ &:rand.uniform/0)

@spec delay(pos_integer(), pos_integer(), pos_integer(), (-> 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.