Returns a Future
that delays the execution of this Future
by the duration t
.
Evaluate this Future
to a result, or another asynchronous computation.
Evaluate this Future
to a result, or another asynchronous computation.
This has the effect of stripping off any 'pure' trampolined computation at
the start of this Future
.
Like step
, but may be interrupted by setting cancel
to true.
Like step
, but may be interrupted by setting cancel
to true.
Returns a Future
which returns a TimeoutException
after timeoutInMillis
,
and attempts to cancel the running computation.
Returns a Future
which returns a TimeoutException
after timeoutInMillis
,
and attempts to cancel the running computation.
This implementation will not block the future's execution thread
Run this Future
, passing the result to the given callback once available.
Run this Future
, passing the result to the given callback once available.
Any pure, non-asynchronous computation at the head of this Future
will
be forced in the calling thread. At the first Async
encountered, control
switches to whatever thread backs the Async
and this function returns.
Run this computation to obtain an A
, so long as cancel
remains false.
Run this computation to obtain an A
, so long as cancel
remains false.
Because of trampolining, we get frequent opportunities to cancel
while stepping through the trampoline, this should provide a fairly
robust means of cancellation.
Run this computation to obtain an A
, then invoke the given callback.
Run this computation to obtain an A
, then invoke the given callback.
Also see unsafePerformAsync
.
Run this computation to obtain an A
, so long as cancel
remains false.
Run this computation to obtain an A
, so long as cancel
remains false.
Because of trampolining, we get frequent opportunities to cancel
while stepping through the trampoline, so this should provide a fairly
robust means of cancellation.
Run this Future
and block awaiting its result.
Like unsafePerformSyncFor
, but returns TimeoutException
as left value.
Like unsafePerformSyncFor
, but returns TimeoutException
as left value.
Will not report any other exceptions that may be raised during computation of A
Run this Future
and block until its result is available, or until
timeoutInMillis
milliseconds have elapsed, at which point a TimeoutException
will be thrown and the Future
will attempt to be canceled.
Begins running this Future
and returns a new future that blocks
waiting for the result.
Begins running this Future
and returns a new future that blocks
waiting for the result. Note that this will start executing side effects
immediately, and is thus morally equivalent to unsafePerformIO
. The
resulting Future
cannot be rerun to repeat the effects.
Use with care.
Future
is a trampolined computation producing anA
that may include asynchronous steps. LikeTrampoline
, arbitrary monadic expressions involvingmap
andflatMap
are guaranteed to use constant stack space. But in addition, one may construct aFuture
from an asynchronous computation, represented as a function,listen: (A => Unit) => Unit
, which registers a callback that will be invoked when the result becomes available. This makesFuture
useful as a concurrency primitive and as a control structure for wrapping callback-based APIs with a more straightforward, monadic API.Unlike the
Future
implementation in scala 2.10,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 viaFuture.fork
orFuture.apply
. This means thatFuture
achieves much better thread reuse than the 2.10 implementation and avoids needless thread pool submit cycles.Future
also differs from the scala 2.10Future
type in that it does not necessarily represent a _running_ computation. Instead, we reintroduce nondeterminism _explicitly_ using the functions of thescalaz.Nondeterminism
interface. This simplifies our implementation and makes code easier to reason about, since the order of effects and the points of nondeterminism are made fully explicit and do not depend on Scala's evaluation order.IMPORTANT NOTE:
Future
does not include any error handling and should generally only be used as a building block by library writers who want to build onFuture
's capabilities but wish to design their own error handling strategy. Seescalaz.concurrent.Task
for a type that extendsFuture
with proper error handling -- it is merely a wrapper forFuture[Throwable \/ A]
with a number of additional convenience functions.