What is best way to run multiple Monix task in parallel and then get one result?
I have the following tasks and want to get a ResultClass.
import monix.eval.Task
val a: Task[A]
val b: Task[B]
val c: Task[C]
case class ResultClass(a:A, b:B, c:C)
The official documentation only has some way to do parallel execution for same type of Tasks.
Is there good way to execute in parallel for different type of Tasks?
Thanks.
Monix Task
has methods like parMap2
, parMap3
, parMap4
up until 6. You could use it like this:
case class ResultClass(a:Int, b:String, c:Boolean)
val a: Task[Int] = Task.pure(1)
val b: Task[String] = Task.pure("Test")
val c: Task[Boolean] = Task.pure(true)
val r: Task[ResultClass] = Task.parMap3(a,b,c)(ResultClass.apply)