Represents a callback that should be called asynchronously with the result of a computation.
Task
represents a specification for an asynchronous computation,
which when executed will produce an A
as a result, along with
possible side-effects.
Task
represents a specification for an asynchronous computation,
which when executed will produce an A
as a result, along with
possible side-effects.
Compared with Future
from Scala's standard library, Task
does
not represent a running computation or a value detached from time,
as Task
does not execute anything when working with its builders
or operators and it does not submit any work into any thread-pool,
the execution eventually taking place only after runAsync
is called and not before that.
Note that Task
is conservative in how it spawns logical threads.
Transformations like map
and flatMap
for example will default
to being executed on the logical thread on which the asynchronous
computation was started. But one shouldn't make assumptions about
how things will end up executed, as ultimately it is the
implementation's job to decide on the best execution model. All
you are guaranteed is asynchronous execution after executing
runAsync
.
Represents a callback that should be called asynchronously with the result of a computation. Used by Task to signal the completion of asynchronous computations on
runAsync
.The
onSuccess
method should be called only once, with the successful result, whereasonError
should be called if the result is an error.