Skip to content

Commit 99ca931

Browse files
committed
don't strongly capture self when handling messages
1 parent b27e922 commit 99ca931

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Sources/SwiftOCA/OCP.1/Ocp1ConnectionMonitor.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,19 @@ extension Ocp1Connection.Monitor {
142142
func receiveMessages(_ connection: Ocp1Connection) async throws {
143143
do {
144144
try await withThrowingTaskGroup(of: Void.self) { group in
145-
group.addTask { [self] in
145+
group.addTask { [weak self] in
146146
repeat {
147147
try Task.checkCancellation()
148148
do {
149-
try await receiveMessage(connection)
149+
try await self?.receiveMessage(connection)
150150
} catch Ocp1Error.invalidHandle {
151151
} catch Ocp1Error.unknownPduType {
152152
} catch Ocp1Error.retryOperation {}
153153
} while true
154154
}
155155
if connection.heartbeatTime > .zero {
156-
group.addTask { [self] in
157-
try await keepAlive(connection)
156+
group.addTask { [weak self] in
157+
try await self?.keepAlive(connection)
158158
}
159159
}
160160
try await group.next()

Sources/SwiftOCADevice/OCP.1/Ocp1ControllerInternal.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ extension Ocp1ControllerInternal {
156156
endpoint.traceMessage(message, controller: self, direction: .rx)
157157
}
158158

159-
let responses = try await messageList.messages.asyncMap { @Sendable message in
159+
let responses = try await messageList.messages.asyncMap { @Sendable [weak self] message in
160160
// note for stream connections this will only throw for invalidMessageType
161-
try await _handle(for: endpoint, message: message)
161+
try await self?._handle(for: endpoint, message: message)
162162
}
163163

164164
if messageList.responseRequired {
@@ -180,8 +180,8 @@ extension Ocp1ControllerInternal {
180180
await withTaskGroup(of: Void.self) { group in
181181
do {
182182
for try await messageList in messages {
183-
group.addTask {
184-
try? await self.handle(for: endpoint, messageList: messageList)
183+
group.addTask { [weak self] in
184+
try? await self?.handle(for: endpoint, messageList: messageList)
185185
}
186186
}
187187
} catch Ocp1Error.notConnected {

0 commit comments

Comments
 (0)