Avatar
@swift-main -Xfrontend -enable-experimental-concurrency import Dispatch func suspendAsync<T>( _ body: (_ continuation: @escaping (T) -> ()) -> () ) async -> T { let semaphore = DispatchSemaphore(value: 0) var result: T! body { value in result = value semaphore.signal() } semaphore.wait() return result } extension DispatchQueue { func asyncAfter(deadline: DispatchTime) async { await suspendAsync { continuation in asyncAfter(deadline: deadline) { continuation(()) } } } } @asyncHandler func main() { print("A") await DispatchQueue.global().asyncAfter(deadline: .now() + 1) print("B") await DispatchQueue.global().asyncAfter(deadline: .now() + 1) print("C") } main()