修复主要流程

This commit is contained in:
anlicheng 2026-05-27 16:37:37 +08:00
parent 5c3276e6b4
commit 4b005cb75d

View File

@ -22,7 +22,6 @@ actor SDLSuperClient {
//
public let messageStream: AsyncThrowingStream<SDLQUICInboundMessage, Error>
private let messageCont: AsyncThrowingStream<SDLQUICInboundMessage, Error>.Continuation
private var isMessageContinuationFinished: Bool = false
private var pendingConnectionError: Error?
@ -107,28 +106,15 @@ actor SDLSuperClient {
self.state = .running
case .failed(let error):
self.pendingConnectionError = SDLSuperError.connectionFailed(error)
self.finishMessageContinuationIfNeed(throwing: .connectionFailed(error))
self.messageCont.finish(throwing: SDLSuperError.connectionFailed(error))
case .cancelled:
self.pendingConnectionError = SDLSuperError.connectionCancelled
self.finishMessageContinuationIfNeed(throwing: .connectionCancelled)
self.messageCont.finish(throwing: SDLSuperError.connectionCancelled)
default:
()
}
}
private func finishMessageContinuationIfNeed(throwing error: SDLSuperError?) {
guard !self.isMessageContinuationFinished else {
return
}
self.isMessageContinuationFinished = true
if let error {
self.messageCont.finish(throwing: error)
} else {
self.messageCont.finish()
}
}
private func waitUntilReady() async throws {
while true {
try Task.checkCancellation()
@ -164,11 +150,12 @@ actor SDLSuperClient {
} catch is CancellationError {
throw CancellationError()
} catch let error as SDLSuperError {
self.finishMessageContinuationIfNeed(throwing: error)
self.messageCont.finish(throwing: error)
throw error
} catch {
let wrappedError = SDLSuperError.internalError(error)
self.finishMessageContinuationIfNeed(throwing: wrappedError)
self.messageCont.finish(throwing: wrappedError)
throw wrappedError
}
}
@ -187,7 +174,7 @@ actor SDLSuperClient {
if let error {
Task {
SDLLogger.log("[SDLSuperClient] send data get error: \(error)", for: .debug)
await self?.finishMessageContinuationIfNeed(throwing: .writeFailed(error))
self?.messageCont.finish(throwing: SDLSuperError.writeFailed(error))
}
}
})
@ -231,8 +218,7 @@ actor SDLSuperClient {
let connection = self.connection
connection.stateUpdateHandler = nil
connection.cancel()
self.finishMessageContinuationIfNeed(throwing: nil)
self.messageCont.finish()
SDLLogger.log("[SDLSuperClient] stopped")
}