ping: switch to async style

because reasons
This commit is contained in:
William Casarin
2023-06-20 11:21:07 +02:00
parent 296d96d6df
commit bcaa1d2354
2 changed files with 18 additions and 7 deletions

View File

@@ -45,8 +45,16 @@ final class WebSocket: NSObject, URLSessionWebSocketDelegate {
self.session = session
}
func ping(receiveHandler: @escaping (Error?) -> Void) {
self.webSocketTask.sendPing(pongReceiveHandler: receiveHandler)
func ping() async throws -> () {
return try await withCheckedThrowingContinuation { cont in
self.webSocketTask.sendPing { err in
if let err {
cont.resume(throwing: err)
} else {
cont.resume(returning: ())
}
}
}
}
func connect() {