From 64bf76a0b53eb281ed34dc27998a86265f495b1f Mon Sep 17 00:00:00 2001 From: Matt Gallagher Date: Thu, 12 Jun 2025 15:40:14 +1000 Subject: [PATCH] Address reference cycle between HubConnection and HttpConnection. --- Sources/SignalRClient/HubConnection.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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")