Revert "ping: switch to async style"
This was causing crashes =/
This commit is contained in:
@@ -56,18 +56,15 @@ final class RelayConnection: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ping() {
|
func ping() {
|
||||||
Task {
|
socket.ping { err in
|
||||||
do {
|
if err == nil {
|
||||||
try await socket.ping()
|
self.last_pong = .now
|
||||||
} catch {
|
} else {
|
||||||
print("pong failed (\(error)), reconnecting \(self.url.id)")
|
print("pong failed, reconnecting \(self.url.id)")
|
||||||
self.isConnected = false
|
self.isConnected = false
|
||||||
self.isConnecting = false
|
self.isConnecting = false
|
||||||
self.reconnect_with_backoff()
|
self.reconnect_with_backoff()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.last_pong = .now
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,16 +45,8 @@ final class WebSocket: NSObject, URLSessionWebSocketDelegate {
|
|||||||
self.session = session
|
self.session = session
|
||||||
}
|
}
|
||||||
|
|
||||||
func ping() async throws -> () {
|
func ping(receiveHandler: @escaping (Error?) -> Void) {
|
||||||
return try await withCheckedThrowingContinuation { cont in
|
self.webSocketTask.sendPing(pongReceiveHandler: receiveHandler)
|
||||||
self.webSocketTask.sendPing { err in
|
|
||||||
if let err {
|
|
||||||
cont.resume(throwing: err)
|
|
||||||
} else {
|
|
||||||
cont.resume(returning: ())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect() {
|
func connect() {
|
||||||
|
|||||||
Reference in New Issue
Block a user