Created
July 4, 2025 13:44
-
-
Save jacobsapps/50312f8f684a67deca607c84a4a53c80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// user IDs not known at compile-time | |
let userIds = getUserIds() // [1, 2, 3, 4, 5] | |
let users = await withTaskGroup(of: User.self) { group in | |
for id in userIds { | |
group.addTask { | |
await fetchUser(id: id) | |
} | |
} | |
var users: [User] = [] | |
for await user in group { | |
users.append(user) | |
} | |
return users | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment