WebsockexNova.Transport.Reconnection.LinearBackoff (WebsockexNova v0.1.0)

View Source

Implements a constant delay reconnection strategy.

This strategy always waits the same amount of time between reconnection attempts. It's simple and predictable but doesn't account for network congestion or other scaling concerns.

Options

  • :delay - Constant delay in milliseconds (default: 1000)
  • :max_retries - Maximum number of retry attempts (default: 5, use :infinity for unlimited)

Summary

Functions

Calculate the delay for a reconnection attempt.

Determines if a reconnection should be attempted.

Types

t()

@type t() :: %WebsockexNova.Transport.Reconnection.LinearBackoff{
  delay: non_neg_integer(),
  max_retries: pos_integer() | :infinity
}

Functions

calculate_delay(linear_backoff, attempt)

@spec calculate_delay(t(), pos_integer()) :: non_neg_integer()

Calculate the delay for a reconnection attempt.

For LinearBackoff, this always returns the same delay regardless of attempt number.

Parameters

  • strategy - The LinearBackoff strategy struct
  • _attempt - The current attempt number (ignored in this strategy)

Returns

  • Constant delay in milliseconds

should_retry?(linear_backoff, attempt)

@spec should_retry?(t(), pos_integer()) :: boolean()

Determines if a reconnection should be attempted.

Parameters

  • strategy - The LinearBackoff strategy struct
  • attempt - The current attempt number (1-based)

Returns

  • true if the attempt number is within the maximum retries
  • false otherwise