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
Taskby 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
attemptand handles some exceptions using the given partial function, calling Task.now on the result.Calls
attemptand 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
attemptand handles some exceptions using the given partial function.Calls
attemptand 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
Taskin whichfis scheduled to be run on completion.Returns a new
Taskin whichfis 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, andflatMapfor 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 predicatepreturnstrue. - 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 predicatepreturnstrue. - 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
Taskwhich returns aTimeoutExceptionaftertimeoutInMillis, 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
Taskwill be forced in the calling thread. At the firstAsyncencountered, control to whatever thread backs theAsyncand 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
TaskInterruptedexception.Note 1: When Interrupted, the
fcallback will run in thread that called theInterruptingfunction () => 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 ascancelremains false.Run this computation to obtain an
A, so long ascancelremains 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
Taskand block until its result is available.Run this
Taskand 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. BothTimeoutExceptionand other exceptions will be folded into the sameThrowable. - def unsafePerformSyncFor(timeout: Duration): A
- def unsafePerformSyncFor(timeoutInMillis: Long): A
Run this
Taskand block until its result is available, or untiltimeoutInMillismilliseconds have elapsed, at which point aTimeoutExceptionwill be thrown and theTaskwill 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