修复主要流程

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