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

Commit 70b6ab2

Browse files
author
Alex Belozierov
committed
- fixed bug
1 parent 53f6858 commit 70b6ab2

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

Sources/SwiftCoroutine/CoFuture/Operators/CoFuture2+await.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ extension CoFuture {
2828
mutex?.unlock()
2929
return try result.get()
3030
}
31-
return try Coroutine.await { (callback: @escaping (Result<Value, Error>) -> Void) in
32-
self.append(callback: callback)
33-
self.mutex?.unlock()
31+
let coroutine: CoroutineProtocol
32+
do {
33+
coroutine = try Coroutine.current()
34+
} catch {
35+
mutex?.unlock()
36+
throw error
37+
}
38+
return try coroutine.await { (callback: @escaping (Result<Value, Error>) -> Void) in
39+
self.append(callback: callback)
40+
self.mutex?.unlock()
3441
}.get()
3542
}
3643

Sources/SwiftCoroutine/Coroutine/TaskScheduler/CoroutineScheduler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension CoroutineScheduler {
5151
/// - Parameter task: The closure that will be executed inside coroutine.
5252
/// If the task throws an error, then the coroutine will be terminated.
5353
@inlinable public func startCoroutine(_ task: @escaping () throws -> Void) {
54-
startCoroutine { do { try task() } catch { print(error) } }
54+
startCoroutine { try? task() }
5555
}
5656

5757
/// Start a coroutine and await its result. Must be called inside other coroutine.

Tests/SwiftCoroutineTests/CoFutureTests/CoFutureCombineTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class CoFutureCombineTests: XCTestCase {
2020

2121
func testSubscribe() {
2222
let exp = expectation(description: "testSubscribe")
23-
exp.expectedFulfillmentCount = 100
24-
for i in 0..<100 {
23+
exp.expectedFulfillmentCount = 1000
24+
for i in 0..<1000 {
2525
let future = Future<Int, Never> { promise in
2626
DispatchQueue.global().asyncAfter(deadline: .now() + .milliseconds(100)) {
2727
promise(.success(i))
@@ -32,7 +32,7 @@ class CoFutureCombineTests: XCTestCase {
3232
exp.fulfill()
3333
}
3434
}
35-
wait(for: [exp], timeout: 3)
35+
wait(for: [exp], timeout: 5)
3636
}
3737

3838
func testSubscription() {

0 commit comments

Comments
 (0)