Post

Replies

Boosts

Views

Activity

Comment on await all barrier primitive for async/await?
I stand corrected. TaskGroup seems like the way to go. But there's definitely an opportunity to build an api that removes some boilerplate (a la bluebirdjs.com): func<T> all(tasks: WhateverTaskType[]) async throws -> T[] { var arr: Array<T> = [] try await withThrowingTaskGroup(of: T.self) { group in for task in tasks { group.async(operation: task) } for try await val in group { arr.append(val) } } return arr }
Jun ’21
Comment on await all barrier primitive for async/await?
The next documentation seems to suggest that it only awaits one of the child tasks, not all of them in parallel. I guess an empty for loop iterating over any AsyncSequence, which uses the next() method, achieves the same thing with a little more boilerplate. After the for loop completes, all the tasks are guaranteed to have completed. In many cases, that's probably enough.
Jun ’21