Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobsapps/6d54d81de5edb9e1f7b526bff9598ac0 to your computer and use it in GitHub Desktop.
Save jacobsapps/6d54d81de5edb9e1f7b526bff9598ac0 to your computer and use it in GitHub Desktop.
Task { // parent task 1
// each of these async lets is a child task of parent task 1
async let name = fetchUserName()
async let avatar = fetchUserAvatar()
try await (name, avatar)
}
Task { // parent task 2
await withTaskGroup(of: Void.self) { group in
for url in urls {
// each task added to the group is a child
// of parent task 2
group.addTask {
try? await fetchItem(from: url)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment