Skip to content

Commit

Permalink
swiftformat cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed May 20, 2024
1 parent 21379c4 commit 56c78ac
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Sources/AutomergeRepo/Networking/Providers/WebSocketProvider.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Automerge
import Network
@preconcurrency import Combine
import Network
import OSLog

/// An Automerge-repo network provider that connects to other repositories using WebSocket.
Expand Down Expand Up @@ -46,7 +46,7 @@ public final class WebSocketProvider: NetworkProvider {
ongoingReceiveMessageTask = nil
peered = false
}

/// Initiate an outgoing connection.
public func connect(to url: URL) async throws {
if peered {
Expand Down Expand Up @@ -361,7 +361,7 @@ public final class WebSocketProvider: NetworkProvider {
// reconnect attempts)
var reconnectAttempts: UInt = 0
var tryToReconnect = config.reconnectOnError

repeat {
msgFromWebSocket = nil

Expand All @@ -373,7 +373,6 @@ public final class WebSocketProvider: NetworkProvider {
tryToReconnect = false
break
}


// if we're not currently peered, attempt to reconnect
// (if we're configured to do so)
Expand All @@ -394,7 +393,7 @@ public final class WebSocketProvider: NetworkProvider {
)
}
reconnectAttempts += 1

do {
// Wait to reconnect. Wait for waitBeforeReconnect and networth path
// transitioning from not satisfied to satisfied. Whichever comes first.
Expand All @@ -404,30 +403,31 @@ public final class WebSocketProvider: NetworkProvider {
group.addTask {
try await Task.sleep(for: .seconds(waitBeforeReconnect))
}

// Wait for network becomming availible
group.addTask {
let monitor = NWPathMonitor()
var last = monitor.currentPath
for await each in monitor.paths() {
if last.status != .satisfied && each.status == .satisfied {
Logger.websocket.info("WEBSOCKET: Network path satisfied while waiting to reconnect")
if last.status != .satisfied, each.status == .satisfied {
Logger.websocket
.info("WEBSOCKET: Network path satisfied while waiting to reconnect")
return
} else {
last = each
}
}
}

// After either task succeeds then cancel group and attempt connection
for try await _ in group {
group.cancelAll()
return try await attemptConnect(to: endpoint)
}

return false
}

if success {
// On successful connection reset connection attemtps
reconnectAttempts = 0
Expand Down Expand Up @@ -471,7 +471,7 @@ public final class WebSocketProvider: NetworkProvider {
}
}
} while tryToReconnect

self.peered = false
webSocketTask?.cancel()
webSocketTask = nil
Expand Down

0 comments on commit 56c78ac

Please sign in to comment.