Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/AvdLee/TaskGroupsResultBuilder
A @resultBuilder to use to bundle tasks together.
https://github.com/AvdLee/TaskGroupsResultBuilder
Last synced: 6 days ago
JSON representation
A @resultBuilder to use to bundle tasks together.
- Host: GitHub
- URL: https://github.com/AvdLee/TaskGroupsResultBuilder
- Owner: AvdLee
- License: mit
- Created: 2023-01-17T08:55:00.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-20T10:24:05.000Z (almost 2 years ago)
- Last Synced: 2024-10-28T14:40:15.303Z (15 days ago)
- Language: Swift
- Size: 13.7 KB
- Stars: 49
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swift-async-await - TaskGroupsResultBuilder
README
# TaskGroupsResultBuilder
***Make sure to read my article on TaskGroups before exploring this project: [Task Groups in Swift explained with code examples](https://www.avanderlee.com/concurrency/task-groups-in-swift/).***This project demonstrates how you can use a [@resultBuilder](https://www.avanderlee.com/swift/result-builders/) in combination with TaskGroup.
### Example
```swift
let photoURLs = try await listPhotoURLs(inGallery: "Amsterdam Holiday")
let images = try await withThrowingTaskGroup {
for photoURL in photoURLs {
Task { try await downloadPhoto(url: photoURL) }
}
}
```Or:
```swift
func taskGroupExampleThree() async {
let names = await withTaskGroup {
Task {
await asyncOperation(name: "Antoine")
}
Task {
await asyncOperation(name: "Maaike")
}
Task {
await asyncOperation(name: "Sep")
}
}
print("Received: \(names)") // Received: ["Antoine", "Maaike", "Sep"]
}
```