Skip to content
Discussion options

You must be logged in to vote

Hey @corysullivan, since the .run closure is provided an async context you can use any and all of Swift's concurrency tools in there. For example, task groups are one way to start up two parallel tasks:

return .run { send in
  await withTaskGroup(Void.self) { group in 
    group.addTask {
      for try await typeA in aAsyncSequence {
        await send(.typeAResult(typeA))
      }
    }
    group.addTask {
      for try await typeB in bAsyncSequence {
        await send(.typeBResult(typeB))
      }
    }
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@corysullivan
Comment options

Answer selected by corysullivan
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