Documentation
¶
Overview ¶
Package backoff provides a reusable exponential backoff calculator with jitter.
This is an internal package and MUST NOT be imported by external consumers. It is used by the Gateway reconnection logic and the rate limiter to compute retry delays that avoid thundering-herd problems.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Calculate ¶
Calculate returns an exponential backoff duration for the given attempt.
The formula is: min(base * 2^attempt + jitter, max)
The jitter is a random duration between 0 and base, added to avoid thundering-herd problems when many clients retry simultaneously.
attempt should be 0-indexed (i.e. the first retry is attempt 0). base is the starting backoff duration before any exponential scaling. max is the upper-bound cap on the returned duration.
If attempt is negative it is treated as 0. If base is zero or negative the returned duration will only contain jitter (capped by max). If max is zero or negative the function returns 0.
Types ¶
This section is empty.