A failed Future
analogous to Predef.???
.
A successfully satisfied constant Unit
-typed Future
of ()
A successfully satisfied constant Future
of false
A successfully satisfied constant Future
of Nil
A successfully satisfied constant Future
of None
A successfully satisfied constant Future
of true
A successfully satisfied constant Unit
-typed Future
of ()
A successfully satisfied constant Future
of Void
-type.
A successfully satisfied constant Future
of Void
-type.
Can be useful for Java programmers.
Creates a satisfied Future
from the result of running a
.
Creates a satisfied Future
from the result of running a
.
If the result of a
is a non-fatal exception,
this will result in a failed Future
. Otherwise, the result
is a successfully satisfied Future
.
that a
is executed in the calling thread and as such
some care must be taken with blocking code.
Creates a "batched" Future that, given a function
Seq[In] => Future[Seq[Out]]
, returns a In => Future[Out]
interface
that batches the underlying asynchronous operations.
Creates a "batched" Future that, given a function
Seq[In] => Future[Seq[Out]]
, returns a In => Future[Out]
interface
that batches the underlying asynchronous operations. Thus, one can
incrementally submit tasks to be performed when the criteria for batch
flushing is met.
Example:
val timer = new JavaTimer(true) def processBatch(reqs: Seq[Request]): Future[Seq[Response]] val batcher = Future.batched(sizeThreshold = 10) { processBatch } val response: Future[Response] = batcher(new Request)
batcher
will wait until 10 requests have been submitted, then delegate
to the processBatch
method to compute the responses.
Batchers can be constructed with both size- or time-based thresholds:
val batcher = Future.batched(sizeThreshold = 10, timeThreshold = 10.milliseconds) { ... }
To force the batcher to immediately process all unprocessed requests:
batcher.flushBatch()
A batcher's size can be controlled at runtime with the sizePercentile
function argument. This function returns a float between 0.0 and 1.0,
representing the fractional size of the sizeThreshold
that should be
used for the next batch to be collected.
Collect the results from the given futures into a new future of Seq[A].
Collect the results from the given futures into a new future of Seq[A]. If one or more of the given futures is exceptional, the resulting future result will be the first exception encountered.
TODO: This method should be deprecated in favour of Futures.collect()
.
a java.util.List of Futures
a Future[java.util.List[A]]
containing the collected values from fs.
Collect the results from the given map fs
of futures into a new future
of map.
Collect the results from the given map fs
of futures into a new future
of map. If one or more of the given Futures is exceptional, the resulting Future
result will the first exception encountered.
a map of Futures
a Future[Map[A, B]]
containing the collected values from fs
Collect the results from the given futures into a new future of
Seq[A]
.
Collect the results from the given futures into a new future of
Seq[A]
. If one or more of the given Futures is exceptional, the resulting
Future result will be the first exception encountered.
a sequence of Futures
a Future[Seq[A]]
containing the collected values from fs.
join if you are not interested in the results of the individual
Futures
, only when they are complete.
collectToTry if you want to be able to see the results of each
Future
regardless of if they succeed or fail.
Collect the results from the given futures into a new future of java.util.List[Try[A]].
Collect the results from the given futures into a new future of java.util.List[Try[A]].
TODO: This method should be deprecated in favour of Futures.collectToTry()
.
a java.util.List of Futures
a Future[java.util.List[Try[A]]]
containing the collected values from fs.
Collect the results from the given futures into a new future of Seq[Try[A]]
.
Collect the results from the given futures into a new future of Seq[Try[A]]
.
The returned Future
is satisfied when all of the given Futures
have been satisfied.
a sequence of Futures
a Future[Seq[Try[A]]]
containing the collected values from fs.
Creates a satisfied Future
from a Try.
Produce values from next
until it fails synchronously
applying body
to each iteration.
Produce values from next
until it fails synchronously
applying body
to each iteration. The returned Future
indicates completion via a failed Future
.
Creates a failed satisfied Future
.
Creates a failed satisfied Future
.
For example,
Future.exception(new Exception("boo"))
.
Future.exception(new Exception("boo")) }}}
apply for creation from a Function
.
Creates a Future
that is satisfied when all futures in fs
are successfully satisfied.
Creates a Future
that is satisfied when all futures in fs
are successfully satisfied. If any of the futures in fs
fail,
the returned Future
is immediately satisfied by that failure.
TODO: This method should be deprecated in favour of Futures.join()
.
a java.util.List of Futures
collectToTry if you want to be able to see the results of each
Future
regardless of if they succeed or fail.
collect if you want to be able to see the results of each Future
.
Futures.join for a Java friendly API.
Join 22 futures.
Join 22 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 21 futures.
Join 21 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 20 futures.
Join 20 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 19 futures.
Join 19 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 18 futures.
Join 18 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 17 futures.
Join 17 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 16 futures.
Join 16 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 15 futures.
Join 15 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 14 futures.
Join 14 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 13 futures.
Join 13 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 12 futures.
Join 12 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 11 futures.
Join 11 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 10 futures.
Join 10 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 9 futures.
Join 9 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 8 futures.
Join 8 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 7 futures.
Join 7 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 6 futures.
Join 6 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 5 futures.
Join 5 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 4 futures.
Join 4 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 3 futures.
Join 3 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Join 2 futures.
Join 2 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
Creates a Future
that is satisfied when all futures in fs
are successfully satisfied.
Creates a Future
that is satisfied when all futures in fs
are successfully satisfied. If any of the futures in fs
fail,
the returned Future
is immediately satisfied by that failure.
a sequence of Futures
collectToTry if you want to be able to see the results of each
Future
regardless of if they succeed or fail.
collect if you want to be able to see the results of each Future
.
Futures.join for a Java friendly API.
Run the computation mkFuture
while installing a Monitor that
translates any exception thrown into an encoded one.
Run the computation mkFuture
while installing a Monitor that
translates any exception thrown into an encoded one. If an
exception is thrown anywhere, the underlying computation is
interrupted with that exception.
This function is usually called to wrap a computation that
returns a Future (f0) whose value is satisfied by the invocation
of an onSuccess/onFailure/ensure callbacks of another future
(f1). If an exception happens in the callbacks on f1, f0 is
never satisfied. In this example, Future.monitored { f1
onSuccess g; f0 }
will cancel f0 so that f0 never hangs.
A Future
that can never be satisfied.
"Select" off the first future to be satisfied.
"Select" off the first future to be satisfied. Return this as a result, with the remainder of the Futures as a sequence.
TODO: This method should be deprecated in favour of Futures.select()
.
a java.util.List
a Future[Tuple2[Try[A], java.util.List[Future[A]]]]
representing the first future
to be satisfied and the rest of the futures.
"Select" off the first future to be satisfied.
"Select" off the first future to be satisfied. Return this as a result, with the remainder of the Futures as a sequence.
the futures to select from. Must not be empty.
selectIndex which can be more performant in some situations.
Select the index into fs
of the first future to be satisfied.
Select the index into fs
of the first future to be satisfied.
cannot be empty
select which can be an easier API to use.
A Unit
-typed Future
that is satisfied after howlong
.
Repeat a computation that returns a Future some number of times, after each computation completes.
Take a sequence and sequentially apply a function f
to each item.
Take a sequence and sequentially apply a function f
to each item.
Then return all future results as
as a single Future[Seq[_]]
.
If during execution any f
is satisfied as
as a failure (Future.exception)
then that failed Future will be returned and the remaining elements of as
will not be processed.
usage:
// will return a Future of `Seq(2, 3, 4)` Future.traverseSequentially(Seq(1, 2, 3)) { i => Future(i + 1) }
a Future[Seq[B]]
containing the results of f
being applied to every item in as
Creates a successful satisfied Future
from the value a
.
Perform the effects of the supplied Future only when the provided flag is true.
Repeat a computation that returns a Future while some predicate obtains, after each computation completes.
The user guide on concurrent programming with Futures.
Futures for Java-friendly APIs.