Future companion object.
Starts an asynchronous computation and returns aFuture instance with the result of that computation.
Starts an asynchronous computation and returns aFuture 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.
the type of the result
the asynchronous computation
the execution context on which the future is run
theFuture holding the result of the computation
Starts an asynchronous computation and returns aFuture instance with the result of that computation once it completes.
Starts an asynchronous computation and returns aFuture instance with the result of that computation once it completes.
The following expressions are semantically equivalent:
val f1 = Future(expr).flattenval f2 = Future.delegate(expr)val f3 = Future.unit.flatMap(_ => expr)The result becomes available once the resulting Future of the asynchronous computation is completed.
the type of the result
the asynchronous computation, returning a Future
the execution context on which thebody is evaluated in
theFuture holding the result of the computation
Creates an already completed Future with the specified exception.
Creates an already completed Future with the specified exception.
the type of the value in the future
the non-null instance ofThrowable
the newly createdFuture instance
Asynchronously and non-blockingly returns aFuture that will hold the optional result of the firstFuture with a result that matches the predicate, failedFutures will be ignored.
Asynchronously and non-blockingly returns aFuture that will hold the optional result of the firstFuture with a result that matches the predicate, failedFutures will be ignored.
the type of the value in the future
thescala.collection.immutable.Iterable of Futures to search
the predicate which indicates if it's a match
theFuture holding the optional result of the search
Asynchronously and non-blockingly returns a newFuture to the result of the first future in the list that is completed.
Asynchronously and non-blockingly returns a newFuture 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.
the type of the value in the future
theIterableOnce of Futures in which to find the first completed
theFuture holding the result of the future that is first to be completed
A non-blocking, asynchronous left fold over the specified futures, with the start value of the given zero.
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)(_ + _)the type of the value of the returnedFuture
the type of the value of the input Futures
thescala.collection.immutable.Iterable of Futures to be folded
the fold operation to be applied to the zero and futures
the start value of the fold
theFuture holding the result of the fold
Creates an already completed Future with the specified result or exception.
Creates an already completed Future with the specified result or exception.
the type of the value in theFuture
the result of the returnedFuture instance
the newly createdFuture instance
Initiates a non-blocking, asynchronous, left reduction over the supplied futures where the zero is the result value of the firstFuture.
Initiates a non-blocking, asynchronous, left reduction over the supplied futures where the zero is the result value of the firstFuture.
Example:
val futureSum = Future.reduceLeft(futures)(_ + _)the type of the value of the returnedFuture
the type of the value of the input Futures
thescala.collection.immutable.Iterable of Futures to be reduced
the reduce operation which is applied to the results of the futures
theFuture holding the result of the reduce
Simple version ofFuture.traverse.
Simple version ofFuture.traverse. Asynchronously and non-blockingly transforms, in essence, aIterableOnce[Future[A]] into aFuture[IterableOnce[A]]. Useful for reducing manyFutures into a singleFuture.
the type of the value inside the Futures
the type of theIterableOnce of Futures
the type of the resulting collection
theIterableOnce of Futures which will be sequenced
theFuture of the resulting collection
Creates an already completed Future with the specified result.
Creates an already completed Future with the specified result.
the type of the value in the future
the given successful value
the newly createdFuture instance
Asynchronously and non-blockingly transforms aIterableOnce[A] into aFuture[IterableOnce[B]] using the provided functionA => Future[B].
Asynchronously and non-blockingly transforms aIterableOnce[A] into aFuture[IterableOnce[B]] using the provided functionA => 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)))the type of the value inside the Futures in the collection
the type of the value of the returnedFuture
the type of the collection of Futures
the function to be mapped over the collection to produce a collection of Futures
the collection to be mapped over with the provided function to produce a collection of Futures that is then sequenced into a Future collection
theFuture of the collection of results
A non-blocking, asynchronous fold over the specified futures, with the start value of the given zero.
A non-blocking, asynchronous fold over the specified futures, with the start value of the given zero. The fold is performed on the thread where the last future is 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.fold(futures)(0)(_ + _)the type of the value of the returnedFuture
the type of the value of the input Futures
theIterableOnce of Futures to be folded
the fold operation to be applied to the zero and futures
the start value of the fold
theFuture holding the result of the fold
[Since version 2.12.0]use Future.foldLeft insteadInitiates a non-blocking, asynchronous, fold over the supplied futures where the fold-zero is the result value of the firstFuture in the collection.
Initiates a non-blocking, asynchronous, fold over the supplied futures where the fold-zero is the result value of the firstFuture in the collection.
Example:
val futureSum = Future.reduce(futures)(_ + _)the type of the value of the returnedFuture
the type of the value of the input Futures
theIterableOnce of Futures to be reduced
the reduce operation which is applied to the results of the futures
theFuture holding the result of the reduce
[Since version 2.12.0]use Future.reduceLeft insteadA Future which is completed with the Unit value.