Remove unused waitForAllResponses & friends

This commit is contained in:
Max Radermacher 2026-05-20 02:28:58 -05:00 committed by GitHub
parent 743c59f545
commit b5d530fb14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 68 deletions

View File

@ -34,11 +34,6 @@ public class SgxWebsocketConnection<Configurator: SgxWebsocketConfigurator> {
fatalError("Concrete subclass must implement")
}
// Subclasses must implement.
func sendRequestAndReadAllResponses(_ request: Configurator.Request) async throws -> [Configurator.Response] {
fatalError("Concrete subclass must implement")
}
// Subclasses must implement.
func disconnect(code: URLSessionWebSocketTask.CloseCode?) {
fatalError("Concrete subclass must implement")
@ -131,17 +126,6 @@ public class SgxWebsocketConnectionImpl<Configurator: SgxWebsocketConfigurator>:
return try Configurator.Response(serializedBytes: data)
}
override public func sendRequestAndReadAllResponses(
_ request: Configurator.Request,
) async throws -> [Configurator.Response] {
try self.encryptAndSendRequest(request.serializedData())
let encryptedResponses = try await self.webSocket.waitForAllResponses().awaitable()
return try encryptedResponses.map {
let data = try self.decryptResponse($0)
return try Configurator.Response(serializedBytes: data)
}
}
private func encryptAndSendRequest(_ request: Data) throws {
let encryptedRequest = try client.establishedSend(request)
webSocket.send(data: encryptedRequest)
@ -184,14 +168,6 @@ public class MockSgxWebsocketConnection<Configurator: SgxWebsocketConfigurator>:
try await onSendRequestAndReadResponse!(request).awaitable()
}
public var onSendRequestAndReadAllResponses: ((Configurator.Request) -> Promise<[Configurator.Response]>)?
override public func sendRequestAndReadAllResponses(
_ request: Configurator.Request,
) async throws -> [Configurator.Response] {
try await onSendRequestAndReadAllResponses!(request).awaitable()
}
public var onDisconnect: (() -> Void)?
override public func disconnect(code: URLSessionWebSocketTask.CloseCode?) {

View File

@ -34,7 +34,7 @@ final class WebSocketPromise: SSKWebSocketDelegate {
/// Initialize a WebSocketPromise & try to connect.
///
/// If an error occurs while connecting, it'll be reported on the first
/// invocation of `waitForResponse`/`waitForAllResponses`.
/// invocation of `waitForResponse`.
init(webSocket: SSKWebSocket) {
self.webSocket = webSocket
webSocket.delegate = self
@ -55,7 +55,6 @@ final class WebSocketPromise: SSKWebSocketDelegate {
private enum WaitingState {
case waitingForResponse(Future<Data>)
case waitingForAllResponses(Future<[Data]>)
}
private struct State {
@ -79,9 +78,9 @@ final class WebSocketPromise: SSKWebSocketDelegate {
/// If a connection failure or write error occurred, it will be reported
/// here in lieu of the next message.
///
/// The caller must ensure that `waitForResponse` and `waitForAllResponses`
/// are called sequentially. After calling one of these methods, the caller
/// must wait until the Promise is resolved before calling either method.
/// The caller must ensure that `waitForResponse` invocations happen
/// sequentially. After calling this method, the caller must wait until the
/// Promise is resolved before calling the method again.
func waitForResponse() -> Promise<Data> {
let (promise, future) = Promise<Data>.pending()
updateState { state in
@ -91,28 +90,6 @@ final class WebSocketPromise: SSKWebSocketDelegate {
return promise
}
/// Read all remaining messages from the underlying web socket.
///
/// If a connection failure or write error occurred, it will be reported
/// here in lieu of the next message.
///
/// The caller must ensure that `waitForResponse` and `waitForAllResponses`
/// are called sequentially. After calling one of these methods, the caller
/// must wait until the Promise is resolved before calling either method.
///
/// - Returns:
/// All remaining messages if the web socket is closed with the
/// `WebSocketError.normalClosure` code. Otherwise, rejects the promise
/// with the error that prevented the socket from closing normally.
func waitForAllResponses() -> Promise<[Data]> {
let (promise, future) = Promise<[Data]>.pending()
updateState { state in
owsPrecondition(state.waitingState == nil)
state.waitingState = .waitingForAllResponses(future)
}
return promise
}
private func updateState(updateBlock: (inout State) -> Void) {
var resolveBlock: (() -> Void)?
state.map { oldState in
@ -150,23 +127,6 @@ final class WebSocketPromise: SSKWebSocketDelegate {
}
// Keep waiting until we receive a message or an error.
return nil
case .waitingForAllResponses(let future):
switch state.socketError {
case .some(WebSocketError.closeError(statusCode: WebSocketError.normalClosure, closeReason: _)):
// On iOS 13 & 14, we expect exactly one message. If we notice "!= 1"
// results on well-behaved platforms, surface it as an error since it's
// probably leading to incorrect behavior on iOS 13 & 14.
owsAssertDebug(state.receivedMessages.count == 1, "Must be exactly one message.")
let receivedMessages = state.receivedMessages
state.receivedMessages = []
return { future.resolve(receivedMessages) }
case .some(let socketError):
return { future.reject(socketError) }
case .none:
break
}
// Keep waiting until the socket is closed.
return nil
}
}