Object

com.thoughtworks.zerocost

task

Related Doc: package zerocost

Permalink

object task

The name space that contains task.Task and utilities for Task.

Usage

Features of task.Task are provided as implicit views or type classes. To enable those features, import all members under task along with Scalaz syntax.

import cats.syntax.all._
import com.thoughtworks.zerocost.task._
Author:

杨博 (Yang Bo)

Source
task.scala
Linear Supertypes
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. task
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

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

    Permalink

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

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

    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
  2. implicit final class ScalaTaskToZeroCostTaskOps[A] extends AnyRef

    Permalink

    Extension methods for scala.concurrent.Future

  3. type Task[+A] = task.OpacityTypes.Task[A]

    Permalink

    An asynchronous task.

    An asynchronous task.

    Note

    Unlike scala.concurrent.Task, this Task is not memoized by default.

    var count = 0
    val notMemoized = Task.delay {
      count += 1
    }
    count should be(0);
    (
      for {
        _ <- notMemoized
        _ = count should be(1)
        _ <- notMemoized
        _ = count should be(2)
        _ <- notMemoized
      } yield (count should be(3))
    ).toFuture
    ,

    A Task can be memoized manually by converting this Task to a scala.concurrent.Task and then converting back.

    var count = 0
    val notMemoized = Task.delay {
      count += 1
    }
    val memoized = notMemoized.toFuture.toTask;
    (
      for {
        _ <- memoized
        _ = count should be(1)
        _ <- memoized
        _ = count should be(1)
        _ <- memoized
      } yield (count should be(1))
    ).toFuture
    See also

    ZeroCostTaskOps for methods available on this Task.

    ParallelTask for parallel version of this Task.

  4. implicit final class UnitContinuationToZeroCostTaskOps[A] extends AnyRef

    Permalink

    Extension methods for UnitContinuation

  5. implicit final class ZeroCostTaskOps[A] extends AnyVal

    Permalink

    Extension methods for Task

Value Members

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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. object Task

    Permalink
  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. implicit def parallelTaskMonadError: MonadError[ParallelTask, Throwable] with LiftIO[ParallelTask]

    Permalink

    Annotations
    @inline()
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  18. implicit def taskMonadError: MonadError[Task, Throwable] with LiftIO[Task]

    Permalink

    Annotations
    @inline()
  19. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Implicit Views

Type class instances

Ungrouped