Skip to content

Commit a041573

Browse files
committed
don't strongly capture self when handling messages
1 parent 28e9e41 commit a041573

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
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/Backend/CF/Ocp1CFController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,16 @@ actor Ocp1CFStreamController: Ocp1CFControllerPrivate, CustomStringConvertible {
118118
connectionPrefix = OcaTcpConnectionPrefix
119119
}
120120

121-
receiveMessageTask = Task { [self] in
121+
receiveMessageTask = Task { [weak self] in
122122
do {
123123
repeat {
124124
let messages = try await OcaDevice
125125
.receiveMessages { try await Array(socket.read(count: $0)) }
126-
_messagesContinuation.yield(messages)
126+
self?._messagesContinuation.yield(messages)
127127
if Task.isCancelled { break }
128128
} while true
129129
} catch {
130-
_messagesContinuation.finish(throwing: error)
130+
self?._messagesContinuation.finish(throwing: error)
131131
}
132132
}
133133
}

Sources/SwiftOCADevice/OCP.1/Backend/IORing/Ocp1IORingController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ actor Ocp1IORingStreamController: Ocp1IORingControllerPrivate, CustomStringConve
110110
connectionPrefix = OcaTcpConnectionPrefix
111111
}
112112

113-
receiveMessageTask = Task {
113+
receiveMessageTask = Task { [weak self] in
114114
do {
115115
repeat {
116116
let messages = try await OcaDevice.receiveMessages { try await socket.read(
117117
count: $0,
118118
awaitingAllRead: true
119119
) }
120-
_messagesContinuation.yield(messages)
120+
self?._messagesContinuation.yield(messages)
121121
if Task.isCancelled { break }
122122
} while true
123123
} catch {
124-
_messagesContinuation.finish(throwing: error)
124+
self?._messagesContinuation.finish(throwing: error)
125125
}
126126
}
127127
}

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)