Packages

final class Task[+A] extends AnyRef

Trampolined computation producing an A that may include asynchronous steps. Arbitrary monadic expressions involving map and flatMap are guaranteed to use constant stack space. In addition, using Task.async, one may construct a Task from callback-based APIs. This makes Task useful as a concurrency primitive and as a control structure for wrapping callback-based APIs with a more straightforward, monadic API.

Task is also exception-safe. Any exceptions raised during processing may be accessed via the attempt method, which converts a Task[A] to a Task[Attempt[A]].

Unlike scala.concurrent.Future, map and flatMap do NOT spawn new tasks and do not require an implicit ExecutionContext. Instead, map and flatMap merely add to the current (trampolined) continuation that will be run by the 'current' thread, unless explicitly forked via Task.start.

Task also differs from scala.concurrent.Future in that it does not represent a _running_ computation. Instead, we reintroduce concurrency _explicitly_ using the Task.start function. This simplifies our implementation and makes code easier to reason about, since the order of effects and the points of allowed concurrency are made fully explicit and do not depend on Scala's evaluation order.

Source
Task.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Task
  2. AnyRef
  3. Any
Implicitly
  1. by JvmSyntax
  2. by any2stringadd
  3. by StringFormat
  4. by Ensuring
  5. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Task(get: Future[Attempt[A]])

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Task[A] to any2stringadd[Task[A]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Task[A], B)
    Implicit
    This member is added by an implicit conversion from Task[A] to ArrowAssoc[Task[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def async(implicit S: Strategy): Task[A]

    Returns a task that performs all evaluation asynchronously.

  8. def attempt: Task[Attempt[A]]

    'Catches' exceptions in the given task and returns them as values.

  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def ensure(failure: ⇒ Throwable)(f: (A) ⇒ Boolean): Task[A]

    Ensures the result of this Task satisfies the given predicate, or fails with the given value.

  11. def ensuring(cond: (Task[A]) ⇒ Boolean, msg: ⇒ Any): Task[A]
    Implicit
    This member is added by an implicit conversion from Task[A] to Ensuring[Task[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: (Task[A]) ⇒ Boolean): Task[A]
    Implicit
    This member is added by an implicit conversion from Task[A] to Ensuring[Task[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: Boolean, msg: ⇒ Any): Task[A]
    Implicit
    This member is added by an implicit conversion from Task[A] to Ensuring[Task[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean): Task[A]
    Implicit
    This member is added by an implicit conversion from Task[A] to Ensuring[Task[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  17. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. def flatMap[B](f: (A) ⇒ Task[B]): Task[B]
  19. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Task[A] to StringFormat[Task[A]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  20. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  21. def handle[B >: A](f: PartialFunction[Throwable, B]): Task[B]

    Calls attempt and handles some exceptions using the given partial function, calling Task.now on the result.

    Calls attempt and handles some exceptions using the given partial function, calling Task.now on the result. Any nonmatching exceptions are reraised.

  22. def handleWith[B >: A](f: PartialFunction[Throwable, Task[B]]): Task[B]

    Calls attempt and handles some exceptions using the given partial function.

    Calls attempt and handles some exceptions using the given partial function. Any nonmatching exceptions are reraised.

  23. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  24. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  25. def map[B](f: (A) ⇒ B): Task[B]
  26. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. final def notify(): Unit
    Definition Classes
    AnyRef
  28. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  29. def or[B >: A](t2: Task[B]): Task[B]

    Runs this Task, and if it fails with an exception, runs t2.

    Runs this Task, and if it fails with an exception, runs t2. This is rather coarse-grained. Use attempt, handle, and flatMap for more fine grained control of exception handling.

  30. def race[B](t: Task[B])(implicit S: Strategy): Task[Either[A, B]]

    Returns a Task that, when run, races evaluation of this and t, and returns the result of whichever completes first.

    Returns a Task that, when run, races evaluation of this and t, and returns the result of whichever completes first. The losing task continues to execute in the background though its result will be sent nowhere.

  31. def schedule(delay: FiniteDuration)(implicit strategy: Strategy, scheduler: Scheduler): Task[A]

    Create a Task that will evaluate a after at least the given delay.

  32. val self: Task[A]
    Implicit
    This member is added by an implicit conversion from Task[A] to Task.JvmSyntax[A] performed by method JvmSyntax in fs2.TaskPlatform.
    Definition Classes
    JvmSyntax
  33. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  34. def toString(): String
    Definition Classes
    Task → AnyRef → Any
  35. def unsafeAttemptRun(): Either[Throwable, A]

    Like unsafeRun, but returns exceptions as values.

    Like unsafeRun, but returns exceptions as values.

    Implicit
    This member is added by an implicit conversion from Task[A] to Task.JvmSyntax[A] performed by method JvmSyntax in fs2.TaskPlatform.
    Definition Classes
    JvmSyntax
  36. def unsafeAttemptRunFor(timeout: FiniteDuration): Either[Throwable, A]

    Like unsafeRunFor, but returns exceptions as values.

    Like unsafeRunFor, but returns exceptions as values. Both TimeoutException and other exceptions will be folded into the same Throwable.

    Implicit
    This member is added by an implicit conversion from Task[A] to Task.JvmSyntax[A] performed by method JvmSyntax in fs2.TaskPlatform.
    Definition Classes
    JvmSyntax
  37. def unsafeAttemptRunSync(): Either[(Callback[A]) ⇒ Unit, Attempt[A]]

    Like unsafeRunSync, but returns exceptions as values.

  38. def unsafeAttemptValue(): Option[Attempt[A]]

    Like unsafeValue, but returns exceptions as values.

  39. def unsafeRun(): A

    Run this Task and block until its result is available.

    Run this Task and block until its result is available. This will throw any exceptions generated by the Task. To return exceptions in an Either, use unsafeAttemptRun().

    Implicit
    This member is added by an implicit conversion from Task[A] to Task.JvmSyntax[A] performed by method JvmSyntax in fs2.TaskPlatform.
    Definition Classes
    JvmSyntax
  40. def unsafeRunAsync(f: (Attempt[A]) ⇒ Unit): Unit

    Run this computation to obtain either a result or an exception, then invoke the given callback.

    Run this computation to obtain either a result or an exception, then invoke the given callback. Any pure, non-asynchronous computation at the head of this Future will be forced in the calling thread. At the first Async encountered, control is transferred to whatever thread backs the Async and this function returns immediately.

  41. def unsafeRunAsyncFuture(): Future[A]

    Run this computation and return the result as a standard library Future.

    Run this computation and return the result as a standard library Future. Like unsafeRunAsync but returns a standard library Future instead of requiring a callback.

  42. def unsafeRunFor(timeout: FiniteDuration): A

    Run this Task and block until its result is available, or until timeout has elapsed, at which point a TimeoutException will be thrown and the Future will attempt to be canceled.

    Run this Task and block until its result is available, or until timeout has elapsed, at which point a TimeoutException will be thrown and the Future will attempt to be canceled.

    Implicit
    This member is added by an implicit conversion from Task[A] to Task.JvmSyntax[A] performed by method JvmSyntax in fs2.TaskPlatform.
    Definition Classes
    JvmSyntax
  43. def unsafeRunSync(): Either[(Callback[A]) ⇒ Unit, A]

    Runs this Task up until an async boundary.

    Runs this Task up until an async boundary. If the task completes synchronously, the result is returned wrapped in a Right. If an async boundary is encountered, a continuation is returned wrapped in a Left. To return exceptions in an Either, use unsafeAttemptRunSync().

  44. def unsafeTimed(timeout: FiniteDuration)(implicit S: Strategy, scheduler: Scheduler): Task[A]

    A Task which returns a TimeoutException after timeout, and attempts to cancel the running computation.

    A Task which returns a TimeoutException after timeout, and attempts to cancel the running computation.

    This method is unsafe because upon reaching the specified timeout, the running task is interrupted at a non-determinstic point in its execution.

  45. def unsafeValue(): Option[A]

    Runs this Task up until an async boundary.

    Runs this Task up until an async boundary. If the task completes synchronously, the result is returned. If an async boundary is encountered, None is returned. To return exceptions in an Either, use unsafeAttemptValue().

  46. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  48. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  49. def [B](y: B): (Task[A], B)
    Implicit
    This member is added by an implicit conversion from Task[A] to ArrowAssoc[Task[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion JvmSyntax from Task[A] to Task.JvmSyntax[A]

Inherited by implicit conversion any2stringadd from Task[A] to any2stringadd[Task[A]]

Inherited by implicit conversion StringFormat from Task[A] to StringFormat[Task[A]]

Inherited by implicit conversion Ensuring from Task[A] to Ensuring[Task[A]]

Inherited by implicit conversion ArrowAssoc from Task[A] to ArrowAssoc[Task[A]]

Ungrouped