Parallel Tasks or TaskGroup

The best way of grouping parallel running tasks that return a value of specific type, and then waiting for the results of all child task?

When asking for “the best way” for something, it’s often impossible to give an (honest) conclusive answer without more concrete context. There are multiple ways of doing parallel computation in Rust, and each of them has their applications / right to exist, so there are multiple “best” ways to do parallel stuff in Rust, with possible trade-offs depending on the concrete use-case, and each way might have specific applications for which it’s “the best way”.

Your question, whilst awfully short of course, give more details than just “what’s the best way to do parallel stuff”, of course; however, you use terminology in ways that – at least for me personally – don’t constitutes a very precise description of what it is you have in mind.

  • what do you mean by “grouping”?
  • what do you mean by “task”?
  • what do you mean by “of specific type”?
  • what do you mean by “TaskGroup” in the title? Is that a technical term, or referring to a particular API of a particular crate?
1 Like

What I meant is that I want to iterate over a collection & run async closure that returns a value on each value of the collection. Something similar to Taskgroup in Swift language :thinking:

If by async you are referring to the same thing as the usage of the same term in the context of Rust usually does, then APIs around streams provided by popular crates are what you are looking for.

Without knowing anything about Swift, and very briefly looking into the TaskGroup type you mentioned, it might be similar to the futures crate’s FuturedUnordered type.

If you don’t need asynchronous but parallel programming (e.g. more processing-heavy and not IO-bound stuff), then async might not be the best tool though.

1 Like

Okay thanks