Skip to content

AvdLee/TaskGroupsResultBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TaskGroupsResultBuilder

Make sure to read my article on TaskGroups before exploring this project: Task Groups in Swift explained with code examples.

This project demonstrates how you can use a @resultBuilder in combination with TaskGroup.

Example

let photoURLs = try await listPhotoURLs(inGallery: "Amsterdam Holiday")
let images = try await withThrowingTaskGroup {
    for photoURL in photoURLs {
        Task { try await downloadPhoto(url: photoURL) }
    }
}

Or:

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"]
}

About

A @resultBuilder to use to bundle tasks together.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages