Files
swift-mirror/test/Concurrency/Runtime/async_taskgroup_throw_rethrow.swift
Doug Gregor 3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -08:00

45 lines
1.1 KiB
Swift

// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
// REQUIRES: CPU=x86_64
import Dispatch
struct Boom: Error {}
struct IgnoredBoom: Error {}
func echo(_ i: Int) async -> Int { i }
func boom() async throws -> Int { throw Boom() }
func test_taskGroup_throws_rethrows() async {
do {
let got = try await Task.withGroup(resultType: Int.self) { (group) async throws -> Int in
await group.add { await echo(1) }
await group.add { await echo(2) }
await group.add { try await boom() }
do {
while let r = try await group.next() {
print("next: \(r)")
}
} catch {
print("error caught and rethrown in group: \(error)")
throw error
}
fatalError("should have thrown")
}
print("got: \(got)")
fatalError("Expected error to be thrown, but got: \(got)")
} catch {
print("rethrown: \(error)")
}
}
// CHECK: error caught and rethrown in group: Boom()
// CHECK: rethrown: Boom()
runAsyncAndBlock(test_taskGroup_throws_rethrows)