This repository was archived by the owner on Feb 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed
Tests/SwiftCoroutineTests/CoFutureTests Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -28,9 +28,16 @@ extension CoFuture {
28
28
mutex? . unlock ( )
29
29
return try result. get ( )
30
30
}
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 ( )
34
41
} . get ( )
35
42
}
36
43
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ extension CoroutineScheduler {
51
51
/// - Parameter task: The closure that will be executed inside coroutine.
52
52
/// If the task throws an error, then the coroutine will be terminated.
53
53
@inlinable public func startCoroutine( _ task: @escaping ( ) throws -> Void ) {
54
- startCoroutine { do { try task ( ) } catch { print ( error ) } }
54
+ startCoroutine { try ? task ( ) }
55
55
}
56
56
57
57
/// Start a coroutine and await its result. Must be called inside other coroutine.
Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ class CoFutureCombineTests: XCTestCase {
20
20
21
21
func testSubscribe( ) {
22
22
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 {
25
25
let future = Future < Int , Never > { promise in
26
26
DispatchQueue . global ( ) . asyncAfter ( deadline: . now( ) + . milliseconds( 100 ) ) {
27
27
promise ( . success( i) )
@@ -32,7 +32,7 @@ class CoFutureCombineTests: XCTestCase {
32
32
exp. fulfill ( )
33
33
}
34
34
}
35
- wait ( for: [ exp] , timeout: 3 )
35
+ wait ( for: [ exp] , timeout: 5 )
36
36
}
37
37
38
38
func testSubscription( ) {
You can’t perform that action at this time.
0 commit comments