Skip to content
Discussion options

You must be logged in to vote

@dpliushchaiIOS Effect.run provides an asynchronous context for you to do async work in, but Task leaves the world of structured concurrency (unless you await the result explicitly, set up cancellation handlers, etc.).

So instead, do the work directly in the task. If you want to parallelize the work done for each item in the loop, you can use a task group, which stays in the structural concurrency world:

case .optimizeCars:
  return .run { [cars = state.uploaderModel.cars] send in
    await withTaskGroup(of: Void.self) { group in
      for car in cars {
        group.addTask {
          do {
            let result = try await environment.optimizer.optimize(
              car: car
        …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Dmitry-Pliushchai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants