Skip to content

Instantly share code, notes, and snippets.

@0xMarK
Created October 29, 2024 16:18
Show Gist options
  • Save 0xMarK/5be565d29d525d89311e0934570461c8 to your computer and use it in GitHub Desktop.
Save 0xMarK/5be565d29d525d89311e0934570461c8 to your computer and use it in GitHub Desktop.
Complicated Task Group
try await withThrowingTaskGroup(of: LoginTaskResult.self) { group in
group.addTask(operation: fetchLocation)
group.addTask(operation: askForUserPermissions)
group.addTask(priority: .high) {
return .client(try await APIClient.connect())
}
var client: APIClient!
for try await result in group {
if case LoginTaskResult.client(let api) = result {
client = api
break
}
}
let tracer = client.traceEvent
group.addTask(operation: client.logUserIn)
group.addTask {
try await tracer(.login)
}
try await group.waitForAll()
_ = try await tracer(.completedLoginSequence)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment