Future companion object.
| Supertypes | |
|---|---|
| Self type |
A Future which is never completed.
Starts an asynchronous computation and returns a Future instance with the result of that computation.
The following expressions are equivalent:
val f1 = Future(expr) val f2 = Future.unit.map(_ => expr) val f3 = Future.unit.transform(_ => Success(expr))
The result becomes available once the asynchronous computation is completed.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
Starts an asynchronous computation and returns a Future instance with the result of that computation once it completes.
The following expressions are semantically equivalent:
val f1 = Future(expr).flatten val f2 = Future.delegate(expr) val f3 = Future.unit.flatMap(_ => expr)
The result becomes available once the resulting Future of the asynchronous computation is completed.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
Creates an already completed Future with the specified exception.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the newly created |
Asynchronously and non-blockingly returns a Future that will hold the optional result of the first Future with a result that matches the predicate, failed Futures will be ignored.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
Asynchronously and non-blockingly returns a new Future to the result of the first future in the list that is completed. This means no matter if it is completed as a success or as a failure.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
A non-blocking, asynchronous left fold over the specified futures, with the start value of the given zero. The fold is performed asynchronously in left-to-right order as the futures become completed. The result will be the first failure of any of the futures, or any failure in the actual fold, or the result of the fold.
Example:
val futureSum = Future.foldLeft(futures)(0)(_ + _)
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
Creates an already completed Future with the specified result or exception.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the newly created |
Initiates a non-blocking, asynchronous, left reduction over the supplied futures where the zero is the result value of the first Future.
Example:
val futureSum = Future.reduceLeft(futures)(_ + _)
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
Simple version of Future.traverse. Asynchronously and non-blockingly transforms, in essence, a IterableOnce[Future[A]] into a Future[IterableOnce[A]]. Useful for reducing many Futures into a single Future.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
Creates an already completed Future with the specified result.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the newly created |
Asynchronously and non-blockingly transforms a IterableOnce[A] into a Future[IterableOnce[B]] using the provided function A => Future[B]. This is useful for performing a parallel map. For example, to apply a function to all items of a list in parallel:
val myFutureList = Future.traverse(myList)(x => Future(myFunc(x)))
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | the |
A Future which is completed with the Unit value.
© 2002-2022 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://scala-lang.org/api/3.2.0/scala/concurrent/Future$.html