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
scalaz.concurrent.Promise and 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
- All
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
attemptRun: \/[Throwable, A]
Like
run, but returns exceptions as values. - def attemptRunFor(timeout: Duration): \/[Throwable, A]
-
def
attemptRunFor(timeoutInMillis: Long): \/[Throwable, A]
Like
runFor, but returns exceptions as values.Like
runFor, but returns exceptions as values. BothTimeoutExceptionand other exceptions will be folded into the sameThrowable. -
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
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: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.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[_]
- Definition Classes
- AnyRef → Any
-
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
-
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
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
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. -
def
run: 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\/, useattemptRun. -
def
runAsync(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
runAsyncInterruptibly(f: (\/[Throwable, A]) ⇒ Unit): () ⇒ Unit
Similar to
runAsyncInterruptibly(f,cancel)except instead of interrupting by setting cancel to true, It returns the function, that, when applied will interrupt the task.Similar to
runAsyncInterruptibly(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 excpetion -
def
runAsyncInterruptibly(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 runFor(timeout: Duration): A
-
def
runFor(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
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
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )