com.thoughtworks.zerocost.task
Parallel-tagged type of Task that needs to be executed in parallel when using an cats.Applicative instance
Given a momoized Task,
import com.thoughtworks.zerocost.task._ val futureA: Task[String] = Task.execute("a").toFuture.toTask
and two ParallelTasks that throw exceptions,
ParallelTask
import com.thoughtworks.zerocost.parallel.Parallel def futureB(a: String): ParallelTask[String] = Parallel(Task.execute { throw new Exception("b failed"); a + "b" }) def futureC(a: String): ParallelTask[String] = Parallel(Task.execute { throw new Exception("c failed"); a + "c" })
and a Task that depends on two String values.
Task
def futureD(b: String, c: String): Task[String] = Task.execute(b + c + "d")
When combining those futures together,
val futureResult = futureA.flatMap { a => val Parallel(tupled) = futureB(a) product futureC(a) tupled.flatMap { case (b, c) => futureD(b, c) } }
then multiple exceptions should be handled together.
futureResult.handleError { case MultipleException(throwables) if throwables.map(_.getMessage) == Set("b failed", "c failed") => "Multiple exceptions handled" }.map { _ should be("Multiple exceptions handled") }.toFuture
Parallel-tagged type of Task that needs to be executed in parallel when using an cats.Applicative instance
Given a momoized Task,
and two
ParallelTask
s that throw exceptions,and a
Task
that depends on two String values.When combining those futures together,
then multiple exceptions should be handled together.