Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 9c395df

Browse files
author
Olexandr Belozierov
committed
- fixed leak in CoroutineScheduler.startCoroutine() when pass CoScope.
1 parent c137153 commit 9c395df

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/SwiftCoroutine/Coroutine/TaskScheduler/CoroutineScheduler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ extension CoroutineScheduler {
6767
/// - task: The closure that will be executed inside coroutine. If the task throws an error, then the coroutine will be terminated.
6868
public func startCoroutine(in scope: CoScope? = nil, task: @escaping () throws -> Void) {
6969
guard let scope = scope else { return _startCoroutine { try? task() } }
70-
_startCoroutine {
70+
_startCoroutine { [weak scope] in
7171
guard let coroutine = try? Coroutine.current(),
72-
let completion = scope.add(coroutine.cancel) else { return }
72+
let completion = scope?.add(coroutine.cancel) else { return }
7373
try? task()
7474
completion()
7575
}

0 commit comments

Comments
 (0)