Packages

object Future

See also

Futures for Java-friendly APIs.

The user guide on concurrent programming with Futures.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Future
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. case class NextThrewException(cause: Throwable) extends IllegalArgumentException with Product with Serializable

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def ???: Future[Nothing]

    A failed Future analogous to Predef.???.

  5. val DEFAULT_TIMEOUT: Duration
  6. val Done: Future[Unit]

    A successfully satisfied constant Unit-typed Future of ()

  7. val False: Future[Boolean]

    A successfully satisfied constant Future of false

  8. val Nil: Future[Seq[Nothing]]

    A successfully satisfied constant Future of Nil

  9. val None: Future[Option[Nothing]]

    A successfully satisfied constant Future of None

  10. val True: Future[Boolean]

    A successfully satisfied constant Future of true

  11. val Unit: Future[Unit]

    A successfully satisfied constant Unit-typed Future of ()

  12. val Void: Future[Void]

    A successfully satisfied constant Future of Void-type.

    A successfully satisfied constant Future of Void-type. Can be useful for Java programmers.

  13. def apply[A](a: => A): Future[A]

    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.

    Note

    that a is executed in the calling thread and as such some care must be taken with blocking code.

  14. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  15. 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 a In => 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 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.

  16. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  17. 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.

  18. 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

  19. 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.

  20. 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.

  21. 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 given Futures have been satisfied.

    fs

    a sequence of Futures

    returns

    a Future[Seq[Try[A]]] containing the collected values from fs.

  22. def const[A](result: Try[A]): Future[A]

    Creates a satisfied Future from a Try.

    Creates a satisfied Future from a Try.

    See also

    value for creation from a constant value.

    apply for creation from a Function.

    exception for creation from a Throwable.

  23. def each[A](next: => Future[A])(body: (A) => Unit): Future[Nothing]

    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.

  24. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  26. 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.

  27. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  28. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  29. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  30. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  31. def join[A](fs: List[Future[A]]): Future[Unit]

    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().

    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.

  32. 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.

  33. 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.

  34. 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.

  35. 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.

  36. 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.

  37. 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.

  38. 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.

  39. 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.

  40. 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.

  41. 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.

  42. 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.

  43. 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.

  44. 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.

  45. 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.

  46. 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.

  47. 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.

  48. 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.

  49. 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.

  50. 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.

  51. 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.

  52. 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.

  53. def join[A](fs: Seq[Future[A]]): Future[Unit]

    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.

    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.

  54. 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.

  55. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  56. val never: Future[Nothing]

    A Future that can never be satisfied.

  57. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  58. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  59. def parallel[A](n: Int)(f: => Future[A]): Seq[Future[A]]
  60. 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.

  61. 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.

  62. 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.

  63. def sleep(howlong: Duration)(implicit timer: Timer): Future[Unit]

    A Unit-typed Future that is satisfied after howlong.

  64. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  65. 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.

  66. def toString(): String
    Definition Classes
    AnyRef → Any
  67. 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 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.value(i + 1)
    }
    returns

    a Future[Seq[B]] containing the results of f being applied to every item in as

  68. def value[A](a: A): Future[A]

    Creates a successful satisfied Future from the value a.

    Creates a successful satisfied Future from the value a.

    See also

    const for creation from a Try

    apply for creation from a Function.

    exception for creation from a Throwable.

  69. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  70. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  71. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  72. def when[A](p: Boolean)(f: => Future[A]): Future[Unit]

    Perform the effects of the supplied Future only when the provided flag is true.

  73. 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.

Inherited from AnyRef

Inherited from Any

Ungrouped