Exponential backoff calculator for reconnection delays.
Usage
backoff = MqttX.Client.Backoff.new(initial: 1000, max: 30_000)
{delay, backoff} = MqttX.Client.Backoff.next(backoff)
# delay = 1000
{delay, backoff} = MqttX.Client.Backoff.next(backoff)
# delay = 2000
backoff = MqttX.Client.Backoff.reset(backoff)
Summary
Functions
Get current delay without advancing.
Create a new backoff calculator.
Get the next delay and update the backoff state.
Reset the backoff to initial state.
Types
@type t() :: %MqttX.Client.Backoff{ current: pos_integer(), initial: pos_integer(), jitter: float(), max: pos_integer(), multiplier: float() }
Functions
@spec current(t()) :: pos_integer()
Get current delay without advancing.
Create a new backoff calculator.
Options
:initial- Initial delay in milliseconds (default: 1000):max- Maximum delay in milliseconds (default: 30000):multiplier- Multiplier for each retry (default: 2.0):jitter- Random jitter factor 0-1 (default: 0.1)
@spec next(t()) :: {pos_integer(), t()}
Get the next delay and update the backoff state.
Returns {delay_ms, new_backoff}.
Reset the backoff to initial state.