You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// non-async function with "weird shape" representing some API that has not adopted
8
+
// swift concurrency yet, but we want to call it from an async function and make it
9
+
// play nice with the rest of the system.
10
+
func someManyCallbacksFunction(
11
+
calledSometimes:()->(),
12
+
otherwiseThisIsCalled:()->(),
13
+
calledOnError:(Error)->()
14
+
){}
15
+
16
+
func test_unsafeContinuations()async{
17
+
// the closure should not allow async operations;
18
+
// after all: if you have async code, just call it directly, without the unsafe continuation
19
+
let _:String=Task.withUnsafeContinuation{ continuation in // expected-error{{cannot convert value of type '(_) async -> ()' to expected argument type '(Task.UnsafeContinuation<String>) -> Void'}}
20
+
lets=awaitsomeAsyncFunc() // rdar://70610141 for getting a better error message here
21
+
continuation.resume(returning: s)
22
+
}
23
+
24
+
let _:String=awaitTask.withUnsafeContinuation{ continuation in
25
+
continuation.resume(returning:"")
26
+
}
27
+
}
28
+
29
+
func test_unsafeThrowingContinuations()async{
30
+
let _:String=tryawaitTask.withUnsafeThrowingContinuation{ continuation in
31
+
continuation.resume(returning:"")
32
+
}
33
+
34
+
let _:String=tryawaitTask.withUnsafeThrowingContinuation{ continuation in
35
+
continuation.resume(throwing:MyError())
36
+
}
37
+
38
+
// TODO: Potentially could offer some warnings if we know that a continuation was resumed or escaped at all in a closure?
0 commit comments