class Task[+A] extends AnyRef
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
.
- Source
- Task.scala
- Alphabetic
- By Inheritance
- Task
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def after(t: Duration): Task[A]
Delays the execution of this
Task
by the durationt
. - final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def attempt: Task[\/[Throwable, A]]
'Catches' exceptions in the given task and returns them as values.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- 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.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatMap[B](f: (A) => Task[B]): Task[B]
- val get: Future[\/[Throwable, A]]
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- 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. - 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. - def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[B](f: (A) => B): Task[B]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def onFinish(f: (Option[Throwable]) => Task[Unit]): Task[A]
Returns a new
Task
in whichf
is scheduled to be run on completion.Returns a new
Task
in whichf
is scheduled to be run on completion. This would typically be used to release any resources acquired by thisTask
. - def or[B >: A](t2: Task[B]): Task[B]
Runs this
Task
, and if it fails with an exception, runst2
.Runs this
Task
, and if it fails with an exception, runst2
. This is rather coarse-grained. Useattempt
,handle
, andflatMap
for more fine grained control of exception handling. - def retry(delays: Seq[Duration], p: (Throwable) => Boolean = _.isInstanceOf[Exception]): Task[A]
Retries this task if it fails, once for each element in
delays
, each retry delayed by the corresponding duration.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 predicatep
returnstrue
. - def retryAccumulating(delays: Seq[Duration], p: (Throwable) => Boolean = _.isInstanceOf[Exception]): 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.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 predicatep
returnstrue
. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def timed(timeout: Duration)(implicit scheduler: ScheduledExecutorService = Strategy.DefaultTimeoutScheduler): Task[A]
- def timed(timeoutInMillis: Long)(implicit scheduler: ScheduledExecutorService): Task[A]
A
Task
which returns aTimeoutException
aftertimeoutInMillis
, and attempts to cancel the running computation. - def toString(): String
- Definition Classes
- AnyRef → Any
- def unsafePerformAsync(f: (\/[Throwable, 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
Task
will be forced in the calling thread. At the firstAsync
encountered, control to whatever thread backs theAsync
and this function returns immediately. - 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 theInterrupting
function () => Unit Note 2: If task has handler like attempt, it won't get consulted for handling TaskInterrupted exception - def unsafePerformAsyncInterruptibly(f: (\/[Throwable, A]) => Unit, cancel: AtomicBoolean): Unit
Run this computation to obtain an
A
, so long ascancel
remains false.Run this computation to obtain an
A
, so long ascancel
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 unsafePerformSync: 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 theTask
. To return exceptions in an\/
, useunsafePerformSyncAttempt
. - def unsafePerformSyncAttempt: \/[Throwable, A]
Like
unsafePerformSync
, but returns exceptions as values. - def unsafePerformSyncAttemptFor(timeout: Duration): \/[Throwable, A]
- def unsafePerformSyncAttemptFor(timeoutInMillis: Long): \/[Throwable, A]
Like
unsafePerformSyncFor
, but returns exceptions as values.Like
unsafePerformSyncFor
, but returns exceptions as values. BothTimeoutException
and other exceptions will be folded into the sameThrowable
. - def unsafePerformSyncFor(timeout: Duration): A
- def unsafePerformSyncFor(timeoutInMillis: Long): A
Run this
Task
and block until its result is available, or untiltimeoutInMillis
milliseconds have elapsed, at which point aTimeoutException
will be thrown and theTask
will attempt to be canceled. - final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Deprecated Value Members
- def attemptRun: \/[Throwable, A]
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformSyncAttempt
- def attemptRunFor(timeout: Duration): \/[Throwable, A]
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformSyncAttemptFor
- def attemptRunFor(timeoutInMillis: Long): \/[Throwable, A]
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformSyncAttemptFor
- def run: A
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformSync
- def runAsync(f: (\/[Throwable, A]) => Unit): Unit
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformAsync
- def runAsyncInterruptibly(f: (\/[Throwable, A]) => Unit): () => Unit
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformAsyncInterruptibly
- def runAsyncInterruptibly(f: (\/[Throwable, A]) => Unit, cancel: AtomicBoolean): Unit
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformAsyncInterruptibly
- def runFor(timeout: Duration): A
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformSyncFor
- def runFor(timeoutInMillis: Long): A
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use unsafePerformSyncFor
- def unsafePerformRetry(delays: Seq[Duration], p: (Throwable) => Boolean = _.isInstanceOf[Exception]): Task[A]
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use retry
- def unsafePerformRetryAccumulating(delays: Seq[Duration], p: (Throwable) => Boolean = _.isInstanceOf[Exception]): Task[(A, List[Throwable])]
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use retryAccumulating
- def unsafePerformTimed(timeoutInMillis: Long)(implicit scheduler: ScheduledExecutorService): Task[A]
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use timed
- def unsafePerformTimed(timeout: Duration)(implicit scheduler: ScheduledExecutorService = Strategy.DefaultTimeoutScheduler): Task[A]
- Annotations
- @deprecated
- Deprecated
(Since version 7.2) use timed