glyde/gateway/backoff

How long a shard waits before its next connection attempt: exponential, capped, half jitter, so the wait lands in [ceiling / 2, ceiling). Full jitter can draw near zero and put a shard back into the failure at once.

Values

pub const attempt_cap: Int

Stops the failure counter growing for the length of an outage. The ladder saturates long before this. Our choice, not Discord’s.

pub fn bump(attempts: Int) -> Int
pub fn delay(
  generator: rng.Rng,
  attempts attempts: Int,
  base base: Int,
  max max: Int,
) -> #(rng.Rng, Int)

The wait before attempt number attempts, where 1 is the first after a connection was lost. base and max are milliseconds. A wait Discord mandates, as after an INVALID_SESSION, is a floor on this, not a second one.

pub fn exhausted(attempts: Int, limit limit: Int) -> Bool

Whether a shard has spent this many attempts in a row without reaching READY. A limit past attempt_cap could never be met, so it is clamped.

Search Document