diff --git a/Sources/SignalRClient/HubConnection.swift b/Sources/SignalRClient/HubConnection.swift index 7ba13d2..8ebe08e 100644 --- a/Sources/SignalRClient/HubConnection.swift +++ b/Sources/SignalRClient/HubConnection.swift @@ -69,8 +69,14 @@ public actor HubConnection { startTask = Task { do { - await self.connection.onClose(handleConnectionClose) - await self.connection.onReceive(processIncomingData) + await self.connection.onClose { [weak self] error in + guard let self else { return } + await self.handleConnectionClose(error: error) + } + await self.connection.onReceive { [weak self] prehandledData in + guard let self else { return } + await self.processIncomingData(prehandledData) + } try await startInternal() logger.log(level: .debug, message: "HubConnection started")