File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,15 @@ public struct UnsafeThrowingContinuation<T> {
47
47
public func resume( returning: __owned T)
48
48
@_silgen_name( " swift_continuation_throw ingResumeWithError" )
49
49
public func resume( throwing: __owned Error)
50
+
51
+ public func resume< E: Error> ( with result: Result < T , E > ) {
52
+ switch result {
53
+ case . success( let val) :
54
+ self . resume ( returning: val)
55
+ case . failure( let err) :
56
+ self . resume ( throwing: err)
57
+ }
58
+ }
50
59
}
51
60
52
61
#if _runtime(_ObjC)
Original file line number Diff line number Diff line change @@ -62,6 +62,16 @@ func test_unsafeThrowingContinuations() async {
62
62
continuation. resume ( throwing: MyError ( ) )
63
63
}
64
64
65
+ // using resume(with:)
66
+ let _: String = try await withUnsafeThrowingContinuation { continuation in
67
+ let result : Result < String , MyError > = . success( " " )
68
+ continuation. resume ( with: result)
69
+ }
70
+
71
+ let _: String = try await withUnsafeThrowingContinuation { continuation in
72
+ continuation. resume ( with: . failure( MyError ( ) ) )
73
+ }
74
+
65
75
// TODO: Potentially could offer some warnings if we know that a continuation was resumed or escaped at all in a closure?
66
76
}
67
77
You can’t perform that action at this time.
0 commit comments