Skip to content

Commit 06609c1

Browse files
committed
Weak
1 parent 7b954da commit 06609c1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/LiveKit/Agent/Session.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ open class Session: ObservableObject {
132132
receivers: receivers)
133133
}
134134

135+
deinit {
136+
waitForAgentTask?.cancel()
137+
}
138+
135139
private func observe(room: Room) {
136140
Task { [weak self] in
137141
for try await _ in room.changes {
@@ -192,9 +196,10 @@ open class Session: ObservableObject {
192196
let timeout = options.agentConnectTimeout
193197

194198
defer {
195-
waitForAgentTask = Task {
199+
waitForAgentTask = Task { [weak self] in
196200
try await Task.sleep(nanoseconds: UInt64(timeout * Double(NSEC_PER_SEC)))
197201
try Task.checkCancellation()
202+
guard let self else { return }
198203
if connectionState == .connected, agents.isEmpty {
199204
self.error = .agentNotConnected
200205
}

0 commit comments

Comments
 (0)