Task

class Task[+A](val get: Future[Throwable \/ A])

Task[A] wraps a scalaz.concurrent.Future[Throwable \/ A], with some convenience functions for handling exceptions. Its Monad and Nondeterminism instances are derived from Future.

Task (and Future) differ in several key ways from the Future implementation in Scala 2.10 , and have a number of advantages. See the documentation for scalaz.concurrent.Future for more information.

Task is exception-safe when constructed using the primitives in the companion object, but when calling the constructor, you are responsible for ensuring the exception safety of the provided Future.

Companion
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def after(t: Duration): Task[A]

Delays the execution of this Task by the duration t.

Delays the execution of this Task by the duration t.

def attempt: Task[Throwable \/ A]

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

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

def ensure(failure: => Throwable)(f: A => Boolean): Task[A]

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

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

def flatMap[B](f: A => Task[B]): Task[B]
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. Any nonmatching exceptions are reraised.

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

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

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

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

def map[B](f: A => B): Task[B]
def onFinish(f: Option[Throwable] => Task[Unit]): Task[A]

Returns a new Task in which f is scheduled to be run on completion. This would typically be used to release any resources acquired by this Task.

Returns a new Task in which f is scheduled to be run on completion. This would typically be used to release any resources acquired by this Task.

def or[B >: A](t2: Task[B]): Task[B]

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.

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.

def retry(delays: Seq[Duration], p: Throwable => Boolean): Task[A]

Retries this task if it fails, once for each element in delays, each retry delayed by the corresponding duration. A retriable failure is one for which the predicate p returns true.

Retries this task if it fails, once for each element in delays, each retry delayed by the corresponding duration. A retriable failure is one for which the predicate p returns true.

def retryAccumulating(delays: Seq[Duration], p: Throwable => Boolean): Task[(A, List[Throwable])]

Retries this task if it fails, once for each element in delays, each retry delayed by the corresponding duration, accumulating errors into a list. A retriable failure is one for which the predicate p returns true.

Retries this task if it fails, once for each element in delays, each retry delayed by the corresponding duration, accumulating errors into a list. A retriable failure is one for which the predicate p returns true.

def timed(timeoutInMillis: Long)(implicit scheduler: ScheduledExecutorService): Task[A]

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

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

def timed(timeout: Duration)(implicit scheduler: ScheduledExecutorService): Task[A]
def unsafePerformAsync(f: Throwable \/ A => Unit): Unit

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 Task will be forced in the calling thread. At the first Async encountered, control to whatever thread backs the Async and this function returns immediately.

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 Task will be forced in the calling thread. At the first Async encountered, control to whatever thread backs the Async and this function returns immediately.

def unsafePerformAsyncInterruptibly(f: Throwable \/ A => Unit, cancel: AtomicBoolean): Unit

Run this computation to obtain an A, so long as cancel remains false. Because of trampolining, we get frequent opportunities to cancel while stepping through the trampoline, this should provide a fairly robust means of cancellation.

Run this computation to obtain an A, so long as cancel remains false. Because of trampolining, we get frequent opportunities to cancel while stepping through the trampoline, this should provide a fairly robust means of cancellation.

def unsafePerformAsyncInterruptibly(f: Throwable \/ A => Unit): () => Unit

Similar to unsafePerformAsyncInterruptibly(f,cancel) except instead of interrupting by setting cancel to true, It returns the function, that, when applied will interrupt the task.

Similar to unsafePerformAsyncInterruptibly(f,cancel) except instead of interrupting by setting cancel to true, It returns the function, that, when applied will interrupt the task.

This allows "deterministic" completion of task computation even if it was interrupted. That means task will complete even when interrupted, but with TaskInterrupted exception.

Note 1: When Interrupted, the f callback will run in thread that called the Interrupting function () => Unit Note 2: If task has handler like attempt, it won't get consulted for handling TaskInterrupted exception

Run this Task and block until its result is available. This will throw any exceptions generated by the Task. To return exceptions in an \/, use unsafePerformSyncAttempt.

Run this Task and block until its result is available. This will throw any exceptions generated by the Task. To return exceptions in an \/, use unsafePerformSyncAttempt.

def unsafePerformSyncAttempt: Throwable \/ A

Like unsafePerformSync, but returns exceptions as values.

Like unsafePerformSync, but returns exceptions as values.

def unsafePerformSyncAttemptFor(timeoutInMillis: Long): Throwable \/ A

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

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

def unsafePerformSyncAttemptFor(timeout: Duration): Throwable \/ A
def unsafePerformSyncFor(timeoutInMillis: Long): A

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

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

def unsafePerformSyncFor(timeout: Duration): A

Deprecated methods

@deprecated("use unsafePerformSyncAttempt", "7.2")
def attemptRun: Throwable \/ A
Deprecated
@deprecated("use unsafePerformSyncAttemptFor", "7.2")
def attemptRunFor(timeoutInMillis: Long): Throwable \/ A
Deprecated
@deprecated("use unsafePerformSyncAttemptFor", "7.2")
def attemptRunFor(timeout: Duration): Throwable \/ A
Deprecated
@deprecated("use unsafePerformSync", "7.2")
def run: A
Deprecated
@deprecated("use unsafePerformAsync", "7.2")
def runAsync(f: Throwable \/ A => Unit): Unit
Deprecated
@deprecated("use unsafePerformAsyncInterruptibly", "7.2")
def runAsyncInterruptibly(f: Throwable \/ A => Unit, cancel: AtomicBoolean): Unit
Deprecated
@deprecated("use unsafePerformAsyncInterruptibly", "7.2")
def runAsyncInterruptibly(f: Throwable \/ A => Unit): () => Unit
Deprecated
@deprecated("use unsafePerformSyncFor", "7.2")
def runFor(timeoutInMillis: Long): A
Deprecated
@deprecated("use unsafePerformSyncFor", "7.2")
def runFor(timeout: Duration): A
Deprecated
@deprecated("use retry", "7.2")
def unsafePerformRetry(delays: Seq[Duration], p: Throwable => Boolean): Task[A]
Deprecated
@deprecated("use retryAccumulating", "7.2")
def unsafePerformRetryAccumulating(delays: Seq[Duration], p: Throwable => Boolean): Task[(A, List[Throwable])]
Deprecated
@deprecated("use timed", "7.2")
def unsafePerformTimed(timeout: Duration)(implicit scheduler: ScheduledExecutorService): Task[A]
Deprecated
@deprecated("use timed", "7.2")
def unsafePerformTimed(timeoutInMillis: Long)(implicit scheduler: ScheduledExecutorService): Task[A]
Deprecated

Concrete fields

val get: Future[Throwable \/ A]