Skip to content

Commit

Permalink
change state to reconnecting before launching detached reconnect task
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Nov 28, 2024
1 parent 65dc953 commit 7422a92
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/SwiftOCA/OCP.1/Ocp1Connection+Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ extension Ocp1Connection {
/// reconnect to the OCA device with exponential backoff, updating
/// connectionState
func reconnectDeviceWithBackoff() async throws {
_updateConnectionState(.reconnecting)

logger
.trace(
"reconnecting: pauseInterval \(options.reconnectPauseInterval) maxTries \(options.reconnectMaxTries) exponentialBackoffThreshold \(options.reconnectExponentialBackoffThreshold)"
Expand Down Expand Up @@ -352,7 +350,9 @@ extension Ocp1Connection {
if _connectionState.value != .notConnected {
// don't update connection state if we were explicitly disconnected
reconnectDevice = _automaticReconnect && error._isRecoverableConnectionError
if !reconnectDevice {
if reconnectDevice {
_updateConnectionState(.reconnecting)
} else {
_updateConnectionState(error.ocp1ConnectionState)
}
try await _disconnectDeviceAfterConnectionFailure()
Expand Down

0 comments on commit 7422a92

Please sign in to comment.