This allows the caller of the method, or creator of the instance of the class, to decide which
ExecutionContext should be used.

For typical REPL usage and experimentation, importing the global ExecutionContext is often desired.

import scala.concurrent.ExcutionContext.Implicits.global

Specifying Durations

Operations often require a duration to be specified. A duration DSL is available
to make defining these easier:

import scala.concurrent.duration._
val d: Duration = 10.seconds

Using Futures For Non-blocking Computation

Basic use of futures is easy with the factory method on Future, which executes a
provided function asynchronously, handing you back a future result of that function
without blocking the current thread. In order to create the Future you will need
either an implicit or explicit ExecutionContext to be provided:

Avoid Blocking

and although this is sometimes necessary to do, in particular for testing purposes, blocking
in general is discouraged when working with Futures and concurrency in order to avoid
potential deadlocks and improve performance. Instead, use callbacks or combinators to
remain in the future domain:

When this future is completed, either through an exception, or a value,
apply the provided function.

When this future is completed, either through an exception, or a value,
apply the provided function.

If the future has already been completed,
this will either be applied immediately or be scheduled asynchronously.

Note that the returned value of f will be discarded.

Since this method executes asynchronously and does not produce a return value,
any non-fatal exceptions thrown will be reported to the ExecutionContext.

Multiple callbacks may be registered; there is no guarantee that they will be
executed in a particular order.

The provided callback always runs in the provided implicit
ExecutionContext, though there is no guarantee that the
execute() method on the ExecutionContext will be called once
per callback or that execute() will be called in the current
thread. That is, the implementation may run multiple callbacks
in a batch within a single execute() and it may run
execute() either immediately or asynchronously.
Completion of the Future must *happen-before* the invocation of the callback.

Creates a new Future by applying the specified function to the result
of this Future.

Creates a new Future by applying the specified function to the result
of this Future. If there is any non-fatal exception thrown when 'f'
is applied then that exception will be propagated to the resulting future.

Creates a new Future by applying the specified function, which produces a Future, to the result
of this Future.

Creates a new Future by applying the specified function, which produces a Future, to the result
of this Future. If there is any non-fatal exception thrown when 'f'
is applied then that exception will be propagated to the resulting future.

If the future was not completed the returned value will be None.
If the future was completed the value will be Some(Success(t))
if it contained a valid result, or Some(Failure(error)) if it contained
an exception.

Equivalent to x.hashCode except for boxed numeric types and null.
For numerics, it returns a hash value which is consistent
with value equality: if two value type instances compare
as true, then ## will produce the same hash value for each
of them.
For null returns a hashcode where null.hashCode throws a
NullPointerException.

Applies the side-effecting function to the result of this future, and returns
a new future with the result of this future.

Applies the side-effecting function to the result of this future, and returns
a new future with the result of this future.

This method allows one to enforce that the callbacks are executed in a
specified order.

Note that if one of the chained andThen callbacks throws
an exception, that exception is not propagated to the subsequent andThen
callbacks. Instead, the subsequent andThen callbacks are given the original
value of this future.

Note that the success of a cast at runtime is modulo Scala's erasure semantics.
Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at
runtime, while the expression List(1).asInstanceOf[List[String]] will not.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the requested type.

Tests whether the argument (that) is a reference to the receiver object (this).

Tests whether the argument (that) is a reference to the receiver object (this).

The eq method implements an equivalence relation on
non-null instances of AnyRef, and has three additional properties:

It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of
x.eq(y) consistently returns true or consistently returns false.

For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false.

null.eq(null) returns true.

When overriding the equals or hashCode methods, it is important to ensure that their behavior is
consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they
should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

returns

true if the argument is a reference to the receiver object; false otherwise.

The returned Future will be successfully completed with the Throwable of the original Future
if the original Future fails.

The returned Future will be successfully completed with the Throwable of the original Future
if the original Future fails.

If the original Future is successful, the returned Future is failed with a NoSuchElementException.

This future may contain a throwable object and this means that the future failed.
Futures obtained through combinators have the same exception as the future they were obtained from.
The following throwable objects are not contained in the future:

Error - errors are not contained within futures

InterruptedException - not contained within futures

all scala.util.control.ControlThrowable except NonLocalReturnControl - not contained within futures

Instead, the future is completed with a ExecutionException with one of the exceptions above
as the cause.
If a future is failed with a scala.runtime.NonLocalReturnControl,
it is completed with a value from that throwable instead.

Creates a new future which holds the result of this future if it was completed successfully, or, if not,
the result of the that future if that is completed successfully.

Creates a new future which holds the result of this future if it was completed successfully, or, if not,
the result of the that future if that is completed successfully.
If both futures are failed, the resulting future holds the throwable object of the first future.

Using this method will not cause concurrent programs to become nondeterministic.

Creates a new future by applying a function to the successful result of
this future, and returns the result of the function as the new future.

Creates a new future by applying a function to the successful result of
this future, and returns the result of the function as the new future.
If this future is completed with an exception then the new future will
also contain this exception.

Note that the result of the test is modulo Scala's erasure semantics.
Therefore the expression 1.isInstanceOf[String] will return false, while the
expression List(1).isInstanceOf[List[String]] will return true.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the specified type.

returns

true if the receiver object is an instance of erasure of type T0; false otherwise.

Creates a String representation of this object. The default
representation is platform dependent. On the java platform it
is the concatenation of the class name, "@", and the object's
hashcode in hexadecimal.

Creates a new future by applying the 's' function to the successful result of
this future, or the 'f' function to the failed result.

Creates a new future by applying the 's' function to the successful result of
this future, or the 'f' function to the failed result. If there is any non-fatal
exception thrown when 's' or 'f' is applied, that exception will be propagated
to the resulting future.

S

the type of the returned Future

s

function that transforms a successful result of the receiver into a successful result of the returned future

f

function that transforms a failure of the receiver into a failure of the returned future

Zips the values of this and that future using a function f,
and creates a new future holding the result.

Zips the values of this and that future using a function f,
and creates a new future holding the result.

If this future fails, the resulting future is failed
with the throwable stored in this.
Otherwise, if that future fails, the resulting future is failed
with the throwable stored in that.
If the application of f throws a throwable, the resulting future
is failed with that throwable if it is non-fatal.

U

the type of the other Future

R

the type of the resulting Future

that

the other Future

f

the function to apply to the results of this and that

returns

a Future with the result of the application of f to the results of this and that

Deprecated Value Members

When this future is completed with a failure (i.e., with a throwable),
apply the provided callback to the throwable.

When this future is completed with a failure (i.e., with a throwable),
apply the provided callback to the throwable.

This future may contain a throwable object and this means that the future failed.
Futures obtained through combinators have the same exception as the future they were obtained from.
The following throwable objects are not contained in the future:

Error - errors are not contained within futures

InterruptedException - not contained within futures

all scala.util.control.ControlThrowable except NonLocalReturnControl - not contained within futures

Instead, the future is completed with a ExecutionException with one of the exceptions above
as the cause.
If a future is failed with a scala.runtime.NonLocalReturnControl,
it is completed with a value from that throwable instead.

If the future has already been completed with a failure,
this will either be applied immediately or be scheduled asynchronously.

Will not be called in case that the future is completed with a value.

Note that the returned value of pf will be discarded.

Since this method executes asynchronously and does not produce a return value,
any non-fatal exceptions thrown will be reported to the ExecutionContext.

Multiple callbacks may be registered; there is no guarantee that they will be
executed in a particular order.

The provided callback always runs in the provided implicit
ExecutionContext, though there is no guarantee that the
execute() method on the ExecutionContext will be called once
per callback or that execute() will be called in the current
thread. That is, the implementation may run multiple callbacks
in a batch within a single execute() and it may run
execute() either immediately or asynchronously.
Completion of the Future must *happen-before* the invocation of the callback.

When this future is completed successfully (i.e., with a value),
apply the provided partial function to the value if the partial function
is defined at that value.

When this future is completed successfully (i.e., with a value),
apply the provided partial function to the value if the partial function
is defined at that value.

If the future has already been completed with a value,
this will either be applied immediately or be scheduled asynchronously.

Note that the returned value of pf will be discarded.

Since this method executes asynchronously and does not produce a return value,
any non-fatal exceptions thrown will be reported to the ExecutionContext.

Multiple callbacks may be registered; there is no guarantee that they will be
executed in a particular order.

The provided callback always runs in the provided implicit
ExecutionContext, though there is no guarantee that the
execute() method on the ExecutionContext will be called once
per callback or that execute() will be called in the current
thread. That is, the implementation may run multiple callbacks
in a batch within a single execute() and it may run
execute() either immediately or asynchronously.
Completion of the Future must *happen-before* the invocation of the callback.