object Future
- See also
Futures for Java-friendly APIs.
The user guide on concurrent programming with Futures.
- Alphabetic
- By Inheritance
- Future
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- case class NextThrewException(cause: Throwable) extends IllegalArgumentException with Product with Serializable
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def ???: Future[Nothing]
A failed
Future
analogous toPredef.???
. - val DEFAULT_TIMEOUT: Duration
- val Done: Future[Unit]
A successfully satisfied constant
Unit
-typedFuture
of()
- val False: Future[Boolean]
A successfully satisfied constant
Future
offalse
- val Nil: Future[Seq[Nothing]]
A successfully satisfied constant
Future
ofNil
- val None: Future[Option[Nothing]]
A successfully satisfied constant
Future
ofNone
- val True: Future[Boolean]
A successfully satisfied constant
Future
oftrue
- val Unit: Future[Unit]
A successfully satisfied constant
Unit
-typedFuture
of()
- val Void: Future[Void]
A successfully satisfied constant
Future
ofVoid
-type.A successfully satisfied constant
Future
ofVoid
-type. Can be useful for Java programmers. - def apply[A](a: => A): Future[A]
Creates a satisfied
Future
from the result of runninga
.Creates a satisfied
Future
from the result of runninga
.If the result of
a
is a non-fatal exception, this will result in a failedFuture
. Otherwise, the result is a successfully satisfiedFuture
.- Note
that
a
is executed in the calling thread and as such some care must be taken with blocking code.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def batched[In, Out](sizeThreshold: Int, timeThreshold: Duration = Duration.Top, sizePercentile: => Float = 1.0f)(f: (Seq[In]) => Future[Seq[Out]])(implicit timer: Timer): Batcher[In, Out]
Creates a "batched" Future that, given a function
scala.collection.Seq[In] => Future[Seq[Out]]
, returns aIn => Future[Out]
interface that batches the underlying asynchronous operations.Creates a "batched" Future that, given a function
scala.collection.Seq[In] => Future[Seq[Out]]
, returns aIn => 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 theprocessBatch
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 thesizeThreshold
that should be used for the next batch to be collected. - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[A](fs: List[Future[A]]): Future[List[A]]
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()
.- fs
a java.util.List of Futures
- returns
a
Future[java.util.List[A]]
containing the collected values from fs.
- def collect[A, B](fs: Map[A, Future[B]]): Future[Map[A, B]]
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.- fs
a map of Futures
- returns
a
Future[Map[A, B]]
containing the collected values from fs
- def collect[A](fs: Seq[Future[A]]): Future[Seq[A]]
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.- fs
a sequence of Futures
- returns
a
Future[Seq[A]]
containing the collected values from fs.
- See also
collectToTry(Seq[Future[A]]) if you want to be able to see the results of each
Future
regardless of if they succeed or fail.join(Seq[A]) if you are not interested in the results of the individual
Futures
, only when they are complete.
- def collectToTry[A](fs: List[Future[A]]): Future[List[Try[A]]]
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()
.- fs
a java.util.List of Futures
- returns
a
Future[java.util.List[Try[A]]]
containing the collected values from fs.
- def collectToTry[A](fs: Seq[Future[A]]): Future[Seq[Try[A]]]
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 givenFutures
have been satisfied.- fs
a sequence of Futures
- returns
a
Future[Seq[Try[A]]]
containing the collected values from fs.
- def const[A](result: Try[A]): Future[A]
Creates a satisfied
Future
from a Try. - def each[A](next: => Future[A])(body: (A) => Unit): Future[Nothing]
Produce values from
next
until it fails synchronously applyingbody
to each iteration.Produce values from
next
until it fails synchronously applyingbody
to each iteration. The returnedFuture
indicates completion via a failedFuture
. - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exception[A](e: Throwable): Future[A]
Creates a failed satisfied
Future
.Creates a failed satisfied
Future
.For example,
Future.exception(new Exception("boo"))
.
Future.exception(new Exception("boo")) }}}
- See also
apply for creation from a
Function
.
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def fromCompletableFuture[T](completableFuture: CompletableFuture[T]): Future[T]
Convert a Java native CompletableFuture to a Twitter Future.
Convert a Java native CompletableFuture to a Twitter Future.
- Note
The Twitter Future's cancellation will be propagated to the underlying CompletableFuture
- See also
https://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html#cancel(boolean)
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def join[A](fs: List[Future[A]]): Future[Unit]
Creates a
Future
that is satisfied when all futures infs
are successfully satisfied.Creates a
Future
that is satisfied when all futures infs
are successfully satisfied. If any of the futures infs
fail, the returnedFuture
is immediately satisfied by that failure.TODO: This method should be deprecated in favour of
Futures.join()
.- fs
a java.util.List of Futures
- See also
Futures.join(Future[A],Future[B]) for a Java friendly API.
collect(Seq[Future[A]]) if you want to be able to see the results of each
Future
.collectToTry(Seq[Future[A]]) if you want to be able to see the results of each
Future
regardless of if they succeed or fail.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O], p: Future[P], q: Future[Q], r: Future[R], s: Future[S], t: Future[T], u: Future[U], v: Future[V]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)]
Join 22 futures.
Join 22 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O], p: Future[P], q: Future[Q], r: Future[R], s: Future[S], t: Future[T], u: Future[U]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)]
Join 21 futures.
Join 21 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O], p: Future[P], q: Future[Q], r: Future[R], s: Future[S], t: Future[T]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)]
Join 20 futures.
Join 20 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O], p: Future[P], q: Future[Q], r: Future[R], s: Future[S]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)]
Join 19 futures.
Join 19 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O], p: Future[P], q: Future[Q], r: Future[R]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)]
Join 18 futures.
Join 18 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O], p: Future[P], q: Future[Q]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)]
Join 17 futures.
Join 17 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O], p: Future[P]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)]
Join 16 futures.
Join 16 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N], o: Future[O]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)]
Join 15 futures.
Join 15 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M, N](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M], n: Future[N]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M, N)]
Join 14 futures.
Join 14 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L, M](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L], m: Future[M]): Future[(A, B, C, D, E, F, G, H, I, J, K, L, M)]
Join 13 futures.
Join 13 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K, L](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K], l: Future[L]): Future[(A, B, C, D, E, F, G, H, I, J, K, L)]
Join 12 futures.
Join 12 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J, K](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J], k: Future[K]): Future[(A, B, C, D, E, F, G, H, I, J, K)]
Join 11 futures.
Join 11 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I, J](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I], j: Future[J]): Future[(A, B, C, D, E, F, G, H, I, J)]
Join 10 futures.
Join 10 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H, I](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H], i: Future[I]): Future[(A, B, C, D, E, F, G, H, I)]
Join 9 futures.
Join 9 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G, H](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G], h: Future[H]): Future[(A, B, C, D, E, F, G, H)]
Join 8 futures.
Join 8 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F, G](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F], g: Future[G]): Future[(A, B, C, D, E, F, G)]
Join 7 futures.
Join 7 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E, F](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E], f: Future[F]): Future[(A, B, C, D, E, F)]
Join 6 futures.
Join 6 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D, E](a: Future[A], b: Future[B], c: Future[C], d: Future[D], e: Future[E]): Future[(A, B, C, D, E)]
Join 5 futures.
Join 5 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C, D](a: Future[A], b: Future[B], c: Future[C], d: Future[D]): Future[(A, B, C, D)]
Join 4 futures.
Join 4 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B, C](a: Future[A], b: Future[B], c: Future[C]): Future[(A, B, C)]
Join 3 futures.
Join 3 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A, B](a: Future[A], b: Future[B]): Future[(A, B)]
Join 2 futures.
Join 2 futures. The returned future is complete when all underlying futures complete. It fails immediately if any of them do.
- def join[A](fs: Seq[Future[A]]): Future[Unit]
Creates a
Future
that is satisfied when all futures infs
are successfully satisfied.Creates a
Future
that is satisfied when all futures infs
are successfully satisfied. If any of the futures infs
fail, the returnedFuture
is immediately satisfied by that failure.- fs
a sequence of Futures
- See also
Futures.join(Future[A],Future[B]) for a Java friendly API.
collect(Seq[Future[A]]) if you want to be able to see the results of each
Future
.collectToTry(Seq[Future[A]]) if you want to be able to see the results of each
Future
regardless of if they succeed or fail.
- def monitored[A](mkFuture: => Future[A]): Future[A]
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. - final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- val never: Future[Nothing]
A
Future
that can never be satisfied. - final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def parallel[A](n: Int)(f: => Future[A]): Seq[Future[A]]
- def select[A](fs: List[Future[A]]): Future[(Try[A], List[Future[A]])]
"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()
.- fs
a java.util.List
- returns
a
Future[Tuple2[Try[A], java.util.List[Future[A]]]]
representing the first future to be satisfied and the rest of the futures.
- def select[A](fs: Seq[Future[A]]): Future[(Try[A], Seq[Future[A]])]
"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.
- fs
the futures to select from. Must not be empty.
- See also
selectIndex which can be more performant in some situations.
- def selectIndex[A](fs: IndexedSeq[Future[A]]): Future[Int]
Select the index into
fs
of the first future to be satisfied.Select the index into
fs
of the first future to be satisfied.- fs
cannot be empty
- See also
select(Seq.MethodPerEndpoint) which can be an easier API to use.
- def sleep(howlong: Duration)(implicit timer: Timer): Future[Unit]
A
Unit
-typedFuture
that is satisfied afterhowlong
. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def times[A](n: Int)(f: => Future[A]): Future[Unit]
Repeat a computation that returns a Future some number of times, after each computation completes.
- def toString(): String
- Definition Classes
- AnyRef → Any
- def traverseSequentially[A, B](as: Seq[A])(f: (A) => Future[B]): Future[Seq[B]]
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 resultsas
as a singleFuture[Seq[_]]
.If during execution any
f
is satisfiedas
as a failure (Future.exception) then that failed Future will be returned and the remaining elements ofas
will not be processed.usage:
// will return a Future of `Seq(2, 3, 4)` Future.traverseSequentially(Seq(1, 2, 3)) { i => Future.value(i + 1) }
- returns
a
Future[Seq[B]]
containing the results off
being applied to every item inas
- def value[A](a: A): Future[A]
Creates a successful satisfied
Future
from the valuea
. - final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def when[A](p: Boolean)(f: => Future[A]): Future[Unit]
Perform the effects of the supplied Future only when the provided flag is true.
- def whileDo[A](p: => Boolean)(f: => Future[A]): Future[Unit]
Repeat a computation that returns a Future while some predicate obtains, after each computation completes.