CancellableFuture
is an object that for all practical uses works like a future but enables the user to cancel the operation.
A cancelled future fails with CancellableFuture.CancelException
so the subscriber can differentiate between this and other
failure reasons. It is impossible to cancel a future if it is already completed or if it is uncancellable.
CancellableFuture
is an object that for all practical uses works like a future but enables the user to cancel the operation.
A cancelled future fails with CancellableFuture.CancelException
so the subscriber can differentiate between this and other
failure reasons. It is impossible to cancel a future if it is already completed or if it is uncancellable.
- See also
Uncancellable
for details on uncancellable futures- Companion
- object
Value members
Abstract methods
Tries to fails the future with the given exception as the failure's reason.
Tries to fails the future with the given exception as the failure's reason.
- Value Params
- th
The reason for the failure
- Returns
true
if the future was cancelled,false
if it was not possible to cancel it
Returns if the future is actually cancellable (not completed and not uncancellable)
Returns if the future is actually cancellable (not completed and not uncancellable)
- See also
Uncancellable
for details on uncancellable futures
Concrete methods
If the future is actually cancellable, adds a timeout after which this future will be cancelled.
In theory, it's possible to add more than one timeout - the shortest one will cancel all others.
Returns the reference to itself so it can be chained with other CancellableFuture
methods.
If the future is actually cancellable, adds a timeout after which this future will be cancelled.
In theory, it's possible to add more than one timeout - the shortest one will cancel all others.
Returns the reference to itself so it can be chained with other CancellableFuture
methods.
- Value Params
- timeout
A time interval after which this future is cancelled if it's cancellable
- Returns
The reference to itself
Tries to cancel the future. If successful, the future fails with CancellableFuture.CancelException
Tries to cancel the future. If successful, the future fails with CancellableFuture.CancelException
- Returns
true
if the future was cancelled,false
if it was not possible to cancel it
Creates a new cancellable future by mapping the value of the current one, if the given partial function
is defined at that value. Otherwise, the resulting cancellable future will fail with a NoSuchElementException
.
Creates a new cancellable future by mapping the value of the current one, if the given partial function
is defined at that value. Otherwise, the resulting cancellable future will fail with a NoSuchElementException
.
- Type Params
- U
The result type of the partial function
pf
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- pf
A partial function which will be applied to the result of the original future if that result belongs to a subset for which the partial function is defined
- Returns
A new cancellable future that will finish with success only if the partial function is applied
- See also
Future.collect
for more - this is its equivalent forCancellableFuture
Creates a new cancellable future by applying the predicate p
to the current one. If the original future
completes with success, but the result does not satisfies the predicate, the resulting future will fail with
a NoSuchElementException
.
Creates a new cancellable future by applying the predicate p
to the current one. If the original future
completes with success, but the result does not satisfies the predicate, the resulting future will fail with
a NoSuchElementException
.
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- p
a predicate function returning a boolean
- Returns
a new cancellable future that will finish with success only if the predicate is satisfied
- See also
Future.filter
for more - this is its equivalent forCancellableFuture
Creates a new cancellable 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 fails or is cancelled, the cancel operation and the result is carried over.
Creates a new cancellable 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 fails or is cancelled, the cancel operation and the result is carried over.
- Type Params
- U
The result type of the function
f
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- f
A function which will be applied to the result of the original future if that result belongs to a subset for which the partial function is defined
- Returns
A new cancellable future that will finish with success only if the partial function is applied
- See also
Future.flatMap
for more - this is its equivalent forCancellableFuture
Flattens a nested cancellable future.
If we have a cancellable future val cf: CancellableFuture[ CancellableFuture[U] ]
with the result of cf
is
another cancellable future - i.e. after executing the original one we will get another future and then we will
execute that, and only then get the result of type U
- then we can use CancellableFuture.flatten
to merge
these two steps into one. As a result, we will have one cancellable future which after successful execution will
give us a result of type U
.
Flattens a nested cancellable future.
If we have a cancellable future val cf: CancellableFuture[ CancellableFuture[U] ]
with the result of cf
is
another cancellable future - i.e. after executing the original one we will get another future and then we will
execute that, and only then get the result of type U
- then we can use CancellableFuture.flatten
to merge
these two steps into one. As a result, we will have one cancellable future which after successful execution will
give us a result of type U
.
- Type Params
- U
The result type of the nested future and the result type of the resulting future
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- Returns
A new cancellable future made from flattening the original one
- See also
Future.flatten
for more - this is its equivalent forCancellableFuture
Same as Future.foreach
.
Same as Future.foreach
.
- Type Params
- U
The result type of
pf
- Value Params
- executor
The execution context in which
pf
will be executed, by default it will be the execution context of this future- pf
The partial function which will be executed when this future is completed with success
- See also
Future
Creates a new cancellable future by applying the f
function to the successful result
of this one. If this future is completed with an exception then the new future will
also contain this exception. If the operation after the cancelling was provided,
it will be carried over to the new cancellable future.
If you cancel this future,
Creates a new cancellable future by applying the f
function to the successful result
of this one. If this future is completed with an exception then the new future will
also contain this exception. If the operation after the cancelling was provided,
it will be carried over to the new cancellable future.
If you cancel this future,
- Type Params
- U
The result type of
f
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- f
The function transforming the result type of this future into the result type of the new one
- Returns
A new cancellable future with the result type
U
being the outcome of the functionf
applied to the result type of this future- See also
Future.map
for more - this is its equivalent forCancellableFuture
Adds a callback for when the future is cancelled (but not failed for any other reason).
There can be more than one onCancel
callback.
Returns the reference to itself so it can be chained with other CancellableFuture
methods.
Adds a callback for when the future is cancelled (but not failed for any other reason).
There can be more than one onCancel
callback.
Returns the reference to itself so it can be chained with other CancellableFuture
methods.
- Value Params
- body
The callback code
- Returns
The reference to itself
Same as Future.onComplete
.
Same as Future.onComplete
.
- Type Params
- U
The result type of
f
- Value Params
- executor
The execution context in which
f
will be executed, by default it will be the execution context of this future- f
The function which will be executed when this future is completed
- See also
Future
Same as Future.ready
.
'''''This method should not be called directly; use Await.ready
instead.'''''
Same as Future.ready
.
'''''This method should not be called directly; use Await.ready
instead.'''''
- Definition Classes
- Awaitable
Creates a new cancellable future that will handle any matching throwable that this future might contain. If there is no match, or if this future contains a valid result then the new future will contain the same. Works also if the current future is cancelled.
Creates a new cancellable future that will handle any matching throwable that this future might contain. If there is no match, or if this future contains a valid result then the new future will contain the same. Works also if the current future is cancelled.
- Type Params
- U
The result type of the partial function
pf
and the result type of the new future ifpf
is defined for theThrowable
returned by the original future
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- pf
A partial function which will be applied to the
Throwable
returned as the failure reason of the original future if that result belongs to a subset for which the partial function is defined. (For example, you can define a partial function that works only on a specific type of exception, i.e. on a subclass ofThrowable
, and for other exceptions the future should really fail).
- Returns
A new cancellable future that will finish with success only if the partial function is applied
- See also
Future.recover
for more - this is its equivalent forCancellableFuture
Creates a new cancellable future that will handle any matching throwable that the current one might contain by assigning it a value of another future. Works also if the current future is cancelled. If there is no match, or if this cancellable future contains a valid result, then the new future will contain the same result.
Creates a new cancellable future that will handle any matching throwable that the current one might contain by assigning it a value of another future. Works also if the current future is cancelled. If there is no match, or if this cancellable future contains a valid result, then the new future will contain the same result.
- Type Params
- U
The result type of the partial function
pf
and the result type of the new future ifpf
is defined for theThrowable
returned by the original future
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- pf
A partial function which will be applied to the
Throwable
returned as the failure reason of the original future if that result belongs to a subset for which the partial function is defined. (For example, you can define a partial function that works only on a specific type of exception, i.e. on a subclass ofThrowable
, and for other exceptions the future should really fail).
- Returns
A new cancellable future that will finish with success only if the partial function is applied
- See also
Future.recoverWith
for more - this is its equivalent forCancellableFuture
Same as Future.result
.
'''''This method should not be called directly; use Await.result
instead.'''''
Same as Future.result
.
'''''This method should not be called directly; use Await.result
instead.'''''
- Definition Classes
- Awaitable
Registers the cancellable future in the given event context. When the event context is stopped, the future will be cancelled. The subscription is also returned so it can be managed manually.
Registers the cancellable future in the given event context. When the event context is stopped, the future will be cancelled. The subscription is also returned so it can be managed manually.
- Value Params
- eventContext
The event context which this future will be subscribed to
- Returns
A
Subscription
representing the connection between the event context and the future. You can use it to cancel the future manually, even if the event context hasn't stopped yet.- See also
EventContext
Creates a new CancellableFuture from the current one and the provided one. The new future completes with success only if both original futures complete with success. If any of the fails or is cancelled, the resulting future fails or is cancelled as well. If the user cancels the resulting future, both original futures are cancelled.
Creates a new CancellableFuture from the current one and the provided one. The new future completes with success only if both original futures complete with success. If any of the fails or is cancelled, the resulting future fails or is cancelled as well. If the user cancels the resulting future, both original futures are cancelled.
- Type Params
- U
the result type of the other future
- Value Params
- executor
The execution context in which the new future will be executed, by default it will be the execution context of this future
- other
The other cancellable future, with the result of the type
U
, that will be zipped with this one
- Returns
A new cancellable future with the result type being a tuple
(T, U)
whereT
is the result type of this future- See also
Future.zip
for more - this is its equivalent forCancellableFuture