Skip to content

Commit a8f1e72

Browse files
committed
fix a few remaining needless awaits
1 parent e27b7d5 commit a8f1e72

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

proposals/0304-structured-concurrency.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func chopVegetables() async throws -> [Vegetable] {
282282
// Create a new child task for each vegetable that needs to be
283283
// chopped.
284284
for v in rawVeggies {
285-
await group.spawn {
285+
group.spawn {
286286
return v.chopped()
287287
}
288288
}
@@ -1033,7 +1033,7 @@ func gather(first m: Int, of work: [Work]) async throws -> [WorkResult] {
10331033

10341034
return withTaskGroup(resultType: WorkResult.self) { group in
10351035
for w in work {
1036-
await group.spawn { await w.doIt() } // spawn child tasks to perform the work
1036+
group.spawn { await w.doIt() } // spawn child tasks to perform the work
10371037
}
10381038

10391039
var results: [WorkResult] = []
@@ -1082,11 +1082,11 @@ func chopVegetables() async throws -> [Vegetable] {
10821082
try await withThrowingTaskGroup(resultType: Vegetable.self) { group in
10831083
print(group.isCancelled) // prints false
10841084

1085-
await group.spawn {
1085+
group.spawn {
10861086
group.cancelAll() // Cancel all work in the group
10871087
throw UnfortunateAccidentWithKnifeError()
10881088
}
1089-
await group.spawn {
1089+
group.spawn {
10901090
return try await chop(Onion())
10911091
}
10921092

@@ -1096,7 +1096,7 @@ func chopVegetables() async throws -> [Vegetable] {
10961096
}
10971097
} catch {
10981098
print(group.isCancelled) // prints true now
1099-
let added = await group.spawn {
1099+
let added = group.spawn {
11001100
return try await chop(SweetPotato())
11011101
}
11021102
print(added) // prints false, no child was added to the cancelled group
@@ -1204,13 +1204,12 @@ func makeDinner() async throws -> Meal {
12041204

12051205
// Create a task group to scope the lifetime of our three child tasks
12061206
try await withTaskGroup(resultType: Void.self) { group in
1207-
await group.spawn {
1208-
veggies = try await chopVegetables()
1209-
}
1210-
await group.spawn {
1207+
group.spawn {
1208+
veggies = try await chgroup.spawn }
1209+
group.spawn {
12111210
meat = await marinateMeat()
12121211
}
1213-
await group.spawn {
1212+
group.spawn {
12141213
oven = await preheatOven(temperature: 350)
12151214
}
12161215
}
@@ -1257,4 +1256,4 @@ Initially the `group.spawn` was designed with the idea of being an asynchronous
12571256

12581257
This was not implemented nor is it clear how efficient and meaningful this form of back-pressure really would be. A naive version of these semantics is possible to implement by balancing pending and completed task counts in the group by plain variables, so removing this implementation doe not prevent developers form implementing such "width limited" operations per se.
12591258

1260-
The way to back-pressure submissions should also be considered in terms of how it relates to async let and general spawn mechanisms, not only groups. We have not figured out this completely, and rather than introduce an not-implemented API which may or may not have the right shape, for now we decided to punt on this feature until we know precisely if and how to apply this style of back-pressure on spawning tasks throughout the system.
1259+
The way to back-pressure submissions should also be considered in terms of how it relates to async let and general spawn mechanisms, not only groups. We have not figured out this completely, and rather than introduce an not-implemented API which may or may not have the right shape, for now we decided to punt on this feature until we know precisely if and how to apply this style of back-pressure on spawning tasks throughout the system.

0 commit comments

Comments
 (0)