Type

com.thoughtworks.zerocost.task

ParallelTask

Related Doc: package task

Permalink

type ParallelTask[A] = Parallel[Task, A]

Parallel-tagged type of Task that needs to be executed in parallel when using an cats.Applicative instance

Source
task.scala
Example:
  1. Given a momoized Task,

    import com.thoughtworks.zerocost.task._
    val futureA: Task[String] = Task.execute("a").toFuture.toTask

    and two ParallelTasks that throw exceptions,

    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.

    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
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getClass(): Class[_]

    Permalink
    Definition Classes
    Any

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  6. def hashCode(): Int

    Permalink
    Definition Classes
    Any
  7. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  8. def toString(): String

    Permalink
    Definition Classes
    Any

Ungrouped