Create a Future
that will evaluate a
using the given Strategy
.
Create a Task
from an asynchronous computation, which takes the form
of a function with which we can register a callback.
Create a Task
from an asynchronous computation, which takes the form
of a function with which we can register a callback. This can be used
to translate from a callback-based API to a straightforward monadic
version. The callback is run using the strategy S
.
Promote a non-strict value to a Task
, catching exceptions in
the process.
Promote a non-strict value to a Task
, catching exceptions in
the process. Note that since Task
is unmemoized, this will
recompute a
each time it is sequenced into a larger computation.
Memoize a
with a lazy value before calling this function if
memoization is desired.
A Task
which fails with the given Throwable
.
Create a Task
from a scala.concurrent.Future
.
Convert a strict value to a Task
.
Convert a strict value to a Task
. Also see delay
.
Create a Task
that will evaluate a
after at least the given delay.
Given t: Task[A]
, start(t)
returns a Task[Task[A]]
.
Given t: Task[A]
, start(t)
returns a Task[Task[A]]
. After flatMap
-ing
into the outer task, t
will be running in the background, and the inner task
is conceptually a future which can be forced at any point via flatMap
.
For example:
for { f <- Task.start { expensiveTask1 } // at this point, `expensive1` is evaluating in background g <- Task.start { expensiveTask2 } // now both `expensiveTask2` and `expensiveTask1` are running result1 <- f // we have forced `f`, so now only `expensiveTask2` may be running result2 <- g // we have forced `g`, so now nothing is running and we have both results } yield (result1 + result2)
Produce f
in the main trampolining loop, Future.step
, using a fresh
call stack.
Produce f
in the main trampolining loop, Future.step
, using a fresh
call stack. The standard trampolining primitive, useful for avoiding
stack overflows.
Like async, but run the callback in the same thread in the same
thread, rather than evaluating the callback using a Strategy
.