BleReconnectPolicy

class BleReconnectPolicy(maxFailures: Int = DEFAULT_MAX_FAILURES, failureThreshold: Int = DEFAULT_FAILURE_THRESHOLD, settleDelay: Duration = DEFAULT_SETTLE_DELAY, val minStableConnection: Duration = DEFAULT_MIN_STABLE_CONNECTION, backoffStrategy: (attempt: Int) -> Duration = ::computeReconnectBackoff)(source)

Encapsulates the BLE reconnection policy with exponential backoff.

The policy tracks consecutive failures and decides whether to retry or signal a transient disconnect (DeviceSleep). When maxFailures is reached the execute loop invokes execute's onPermanentDisconnect callback and returns; set maxFailures to Int.MAX_VALUE (as BleRadioTransport does) to disable the give-up path entirely.

Parameters

maxFailures

maximum consecutive failures before giving up; use Int.MAX_VALUE to retry indefinitely

failureThreshold

after this many consecutive failures, signal a transient disconnect

settleDelay

delay before each connection attempt to let the BLE stack settle

minStableConnection

minimum time a connection must stay up to be considered "stable"

backoffStrategy

computes the backoff delay for a given failure count

Constructors

Link copied to clipboard
constructor(maxFailures: Int = DEFAULT_MAX_FAILURES, failureThreshold: Int = DEFAULT_FAILURE_THRESHOLD, settleDelay: Duration = DEFAULT_SETTLE_DELAY, minStableConnection: Duration = DEFAULT_MIN_STABLE_CONNECTION, backoffStrategy: (attempt: Int) -> Duration = ::computeReconnectBackoff)

Types

Link copied to clipboard
sealed interface Action

Action the caller should take after the policy processes an outcome.

Link copied to clipboard
object Companion
Link copied to clipboard
sealed interface Outcome

Outcome of a single reconnect iteration.

Properties

Link copied to clipboard

Minimum time a connection must stay up to be considered "stable". Exposed for callers to compare uptime.

Functions

Link copied to clipboard
suspend fun execute(attempt: suspend () -> BleReconnectPolicy.Outcome, onTransientDisconnect: suspend (Throwable?) -> Unit, onPermanentDisconnect: suspend (Throwable?) -> Unit)

Runs the reconnect loop, calling attempt for each iteration.

Link copied to clipboard

Processes the outcome of a connection attempt and returns the action the caller should take.