Skip to content

Simplify usages of withTaskGroup to infer ChildTaskResult type where possible #1102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Testing/Running/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ extension Runner {
in sequence: some Sequence<E>,
_ body: @Sendable @escaping (E) async throws -> Void
) async throws where E: Sendable {
try await withThrowingTaskGroup(of: Void.self) { taskGroup in
try await withThrowingTaskGroup { taskGroup in
for element in sequence {
// Each element gets its own subtask to run in.
_ = taskGroup.addTaskUnlessCancelled {
Expand Down Expand Up @@ -430,7 +430,7 @@ extension Runner {
Event.post(.iterationEnded(iterationIndex), for: (nil, nil), configuration: runner.configuration)
}

await withTaskGroup(of: Void.self) { [runner] taskGroup in
await withTaskGroup { [runner] taskGroup in
_ = taskGroup.addTaskUnlessCancelled {
try? await _runStep(atRootOf: runner.plan.stepGraph)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Testing/Test+Discovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension Test {
// a task group and collate their results.
if useNewMode {
let generators = Generator.allTestContentRecords().lazy.compactMap { $0.load() }
await withTaskGroup(of: Self.self) { taskGroup in
await withTaskGroup { taskGroup in
for generator in generators {
taskGroup.addTask { await generator.rawValue() }
}
Expand All @@ -96,7 +96,7 @@ extension Test {
// Perform legacy test discovery if needed.
if useLegacyMode && result.isEmpty {
let generators = Generator.allTypeMetadataBasedTestContentRecords().lazy.compactMap { $0.load() }
await withTaskGroup(of: Self.self) { taskGroup in
await withTaskGroup { taskGroup in
for generator in generators {
taskGroup.addTask { await generator.rawValue() }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Testing/Traits/TimeLimitTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func withTimeLimit(
_ body: @escaping @Sendable () async throws -> Void,
timeoutHandler: @escaping @Sendable () -> Void
) async throws {
try await withThrowingTaskGroup(of: Void.self) { group in
try await withThrowingTaskGroup { group in
group.addTask {
// If sleep() returns instead of throwing a CancellationError, that means
// the timeout was reached before this task could be cancelled, so call
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingTests/Support/CartesianProductTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct CartesianProductTests {
// Test that the product can be iterated multiple times concurrently.
let (_, _, product) = computeCartesianProduct()
let expectedSum = product.reduce(into: 0) { $0 &+= $1.1 }
await withTaskGroup(of: Int.self) { taskGroup in
await withTaskGroup { taskGroup in
for _ in 0 ..< 10 {
taskGroup.addTask {
product.reduce(into: 0) { $0 &+= $1.1 }
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingTests/Support/LockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct LockTests {
@Test("No lock")
func noLock() async {
let lock = LockedWith<Never, Int>(rawValue: 0)
await withTaskGroup(of: Void.self) { taskGroup in
await withTaskGroup { taskGroup in
for _ in 0 ..< 100_000 {
taskGroup.addTask {
lock.increment()
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingTests/Traits/TimeLimitTraitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct TimeLimitTraitTests {
@Test("Cancelled tests can exit early (cancellation checking works)")
func cancelledTestExitsEarly() async throws {
let timeAwaited = await Test.Clock().measure {
await withTaskGroup(of: Void.self) { taskGroup in
await withTaskGroup { taskGroup in
taskGroup.addTask {
await Test {
try await Test.Clock.sleep(for: .seconds(60) * 60)
Expand Down