Returns a task that performs all evaluation asynchronously.
'Catches' exceptions in the given task and returns them as values.
Ensures the result of this Task satisfies the given predicate, or fails with the given value.
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.
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.
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.
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.
Create a Task
that will evaluate a
after at least the given delay.
Like unsafeRun
, but returns exceptions as values.
Like unsafeRun
, but returns exceptions as values.
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
.
Like unsafeRunSync
, but returns exceptions as values.
Like unsafeValue
, but returns exceptions as values.
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()
.
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.
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.
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.
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()
.
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.
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()
.
Trampolined computation producing an
A
that may include asynchronous steps. Arbitrary monadic expressions involvingmap
andflatMap
are guaranteed to use constant stack space. In addition, usingTask.async
, one may construct aTask
from callback-based APIs. This makesTask
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 aTask[A]
to aTask[Attempt[A]]
.Unlike
scala.concurrent.Future
,map
andflatMap
do NOT spawn new tasks and do not require an implicitExecutionContext
. Instead,map
andflatMap
merely add to the current (trampolined) continuation that will be run by the 'current' thread, unless explicitly forked viaTask.start
.Task
also differs fromscala.concurrent.Future
in that it does not represent a _running_ computation. Instead, we reintroduce concurrency _explicitly_ using theTask.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.