Class ExtendedFuture<T>
- java.lang.Object
-
- java.util.concurrent.CompletableFuture<T>
-
- io.github.futures4j.ExtendedFuture<T>
-
- Type Parameters:
T
- the result type returned by thisExtendedFuture
- All Implemented Interfaces:
CompletionStage<T>
,Future<T>
- Direct Known Subclasses:
Futures.CombinedFuture
public class ExtendedFuture<T> extends CompletableFuture<T>
An enhanced version ofCompletableFuture
providing additional features:- Interruptible Tasks: Allows task thread interruption via
cancel(true)
. This behavior is controllable usingasNonInterruptible()
andwithInterruptibleStages(boolean)
. - Dependent Stage Cancellation: Enables dependent stages to cancel preceding stages, controllable via
asCancellableByDependents(boolean)
. - Checked Exceptions: Supports running tasks that throw checked exceptions, e.g.,
runAsync(ThrowingRunnable)
. - Read-Only Views: Allows creating read-only views of a future using
asReadOnly(ReadOnlyMode)
. - Default Executor: Enables defining a default executor for this future and all subsequent stages via
withDefaultExecutor(Executor)
orExtendedFuture.Builder.withDefaultExecutor(Executor)
. - Convenience Methods: Offers additional methods such as
completeWith(CompletableFuture)
,isSuccess()
,isFailed()
,getNowOptional()
,getNowOrFallback(Object)
,getOptional(long, TimeUnit)
,getOrFallback(Object)
, andgetOrFallback(Object, long, TimeUnit)
.
For more information on issues addressed by this class, refer to the following resources:
- https://stackoverflow.com/questions/25417881/canceling-a-completablefuture-chain
- https://stackoverflow.com/questions/36727820/cancellation-of-completablefuture-controlled-by-executorservice
- https://stackoverflow.com/questions/62106428/is-there-a-better-way-for-cancelling-a-chain-of-futures-in-java
- https://stackoverflow.com/questions/29013831/how-to-interrupt-underlying-execution-of-completablefuture
- https://nurkiewicz.com/2015/03/completablefuture-cant-be-interrupted.html
- https://blog.tremblay.pro/2017/08/supply-async.html
- Author:
- Sebastian Thomschke
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExtendedFuture.Builder<V>
A builder for constructing customizedExtendedFuture
instances with specific configurations.static class
ExtendedFuture.ReadOnlyMode
Modes for creating a read-only view of anExtendedFuture
.-
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
cancellableByDependents
protected Collection<Future<?>>
cancellablePrecedingStages
protected Executor
defaultExecutor
protected boolean
interruptibleStages
-
Constructor Summary
Constructors Constructor Description ExtendedFuture()
Creates a newExtendedFuture
with default settings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtendedFuture<@Nullable Void>
acceptEither(CompletionStage<? extends T> other, ThrowingConsumer<? super T,?> action)
ExtendedFuture<@Nullable Void>
acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)
ExtendedFuture<@Nullable Void>
acceptEitherAsync(CompletionStage<? extends T> other, ThrowingConsumer<? super T,?> action)
ExtendedFuture<@Nullable Void>
acceptEitherAsync(CompletionStage<? extends T> other, ThrowingConsumer<? super T,?> action, Executor executor)
ExtendedFuture<@Nullable Void>
acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)
ExtendedFuture<@Nullable Void>
acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)
ExtendedFuture<T>
addTo(Futures.Combiner<T> combiner)
Adds this future to the givenFutures.Combiner
.ExtendedFuture<T>
addTo(Consumer<Future<T>> consumer)
Passes this future to the givenConsumer
.static ExtendedFuture<@Nullable Void>
allOf(CompletableFuture<?>... cfs)
Returns a newExtendedFuture
that completes when all of the given futures complete.static ExtendedFuture<@Nullable Object>
anyOf(CompletableFuture<?>... cfs)
Returns a newExtendedFuture
that completes when any of the given futures complete.<U> ExtendedFuture<U>
applyToEither(CompletionStage<? extends T> other, ThrowingFunction<? super T,U,?> fn)
<U> ExtendedFuture<U>
applyToEither(CompletionStage<? extends T> other, Function<? super T,U> fn)
<U> ExtendedFuture<U>
applyToEitherAsync(CompletionStage<? extends T> other, ThrowingFunction<? super T,U,?> fn)
<U> ExtendedFuture<U>
applyToEitherAsync(CompletionStage<? extends T> other, ThrowingFunction<? super T,U,?> fn, Executor executor)
<U> ExtendedFuture<U>
applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn)
<U> ExtendedFuture<U>
applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)
ExtendedFuture<T>
asCancellableByDependents(boolean isCancellableByDependents)
Returns anExtendedFuture
that shares the result with this future but allows control over whether cancellation of dependent stages cancels this future.ExtendedFuture<T>
asNonInterruptible()
Returns anExtendedFuture
that shares the result with this future but ensures that this future cannot be interrupted, i.e., callingcancel(true)
will not result in a thread interruption.ExtendedFuture<T>
asReadOnly(ExtendedFuture.ReadOnlyMode readOnlyMode)
Creates a read-only view of thisExtendedFuture
.static <V> ExtendedFuture.Builder<V>
builder(Class<V> targetType)
Creates a newExtendedFuture.Builder
for constructing anExtendedFuture
.boolean
cancel(boolean mayInterruptIfRunning)
boolean
complete(T value)
Completes this future with the given value if not already completed.ExtendedFuture<T>
completeAsync(ThrowingSupplier<? extends T,?> supplier)
Completes this future with the result of the given throwing supplier function, running it asynchronously using the default executor.ExtendedFuture<T>
completeAsync(ThrowingSupplier<? extends T,?> supplier, Executor executor)
Completes this future with the result of the given throwing supplier function, running it asynchronously using the specified executor.ExtendedFuture<T>
completeAsync(Supplier<? extends T> supplier)
Completes this future with the result of the given supplier function, running it asynchronously using the default executor.ExtendedFuture<T>
completeAsync(Supplier<? extends T> supplier, Executor executor)
Completes this future with the result of the given supplier function, running it asynchronously using the specified executor.static <V> ExtendedFuture<V>
completedFuture(V value)
Returns a completedExtendedFuture
with the given value.boolean
completeExceptionally(Throwable ex)
Completes this future exceptionally with the given exception if not already completed.ExtendedFuture<T>
completeOnTimeout(T value, long timeout, TimeUnit unit)
ExtendedFuture<T>
completeWith(CompletableFuture<? extends T> future)
Completes thisExtendedFuture
when the providedCompletableFuture
finishes, with either its result or its exception.ExtendedFuture<T>
copy()
Executor
defaultExecutor()
ExtendedFuture<T>
exceptionally(ThrowingFunction<Throwable,? extends T,?> fn)
ExtendedFuture<T>
exceptionally(Function<Throwable,? extends T> fn)
ExtendedFuture<T>
exceptionallyAsync(ThrowingFunction<Throwable,? extends T,?> fn)
ExtendedFuture<T>
exceptionallyAsync(ThrowingFunction<Throwable,? extends T,?> fn, Executor executor)
ExtendedFuture<T>
exceptionallyAsync(Function<Throwable,? extends T> fn)
This method emulates theCompletableFuture
's exceptionallyAsync method introduced in Java 12.ExtendedFuture<T>
exceptionallyAsync(Function<Throwable,? extends T> fn, Executor executor)
This method emulates theCompletableFuture
's exceptionallyAsync method introduced in Java 12.ExtendedFuture<T>
exceptionallyCompose(ThrowingFunction<Throwable,? extends CompletionStage<T>,?> fn)
ExtendedFuture<T>
exceptionallyCompose(Function<Throwable,? extends CompletionStage<T>> fn)
This method emulates theCompletableFuture
's exceptionallyCompose method introduced in Java 12.ExtendedFuture<T>
exceptionallyComposeAsync(ThrowingFunction<Throwable,? extends CompletionStage<T>,?> fn)
ExtendedFuture<T>
exceptionallyComposeAsync(ThrowingFunction<Throwable,? extends CompletionStage<T>,?> fn, Executor executor)
ExtendedFuture<T>
exceptionallyComposeAsync(Function<Throwable,? extends CompletionStage<T>> fn)
This method emulates theCompletableFuture
's exceptionallyComposeAsync method introduced in Java 12.ExtendedFuture<T>
exceptionallyComposeAsync(Function<Throwable,? extends CompletionStage<T>> fn, Executor executor)
This method emulates theCompletableFuture
's exceptionallyComposeAsync method introduced in Java 12.Throwable
exceptionNow()
This method emulates theCompletableFuture
's exceptionNow method introduced in Java 19.static <V> ExtendedFuture<V>
failedFuture(Throwable ex)
Returns a completedExtendedFuture
that has completed exceptionally with the given exception.ExtendedFuture<T>
forwardCancellation(@Nullable Future<?> to)
Propagates the cancellation of thisExtendedFuture
to anotherFuture
.ExtendedFuture<T>
forwardCancellation(Future<?> @Nullable ... to)
Propagates the cancellation of thisExtendedFuture
to otherFuture
s.ExtendedFuture<T>
forwardCancellationTo(@Nullable Collection<? extends @Nullable Future<?>> to)
Propagates the cancellation of thisExtendedFuture
to otherFuture
s.static <V> ExtendedFuture<V>
from(CompletableFuture<V> source)
Wraps a givenCompletableFuture
into anExtendedFuture
.Optional<T>
getNowOptional()
T
getNowOrComputeFallback(BiFunction<Future<T>,@Nullable Exception,T> fallbackComputer)
Returns the result of this future if it is already completed, or the value provided byfallbackComputer
if the future is incomplete, cancelled or failed.T
getNowOrComputeFallback(Function<@Nullable Exception,T> fallbackComputer)
Returns the result of this future if it is already completed, or the value provided byfallbackComputer
if the future is incomplete, cancelled or failed.T
getNowOrFallback(T fallback)
Returns the result of this future if it is already completed, or the specifiedfallback
if the future is incomplete, cancelled or failed.Optional<T>
getOptional()
Attempts to retrieve the result this future within the specified timeout.Optional<T>
getOptional(long timeout, TimeUnit unit)
Attempts to retrieve the result this future within the specified timeout.T
getOrComputeFallback(BiFunction<Future<T>,@Nullable Exception,T> fallbackComputer)
Attempts to retrieve the result of this future.T
getOrComputeFallback(BiFunction<Future<T>,@Nullable Exception,T> fallbackComputer, long timeout, TimeUnit unit)
Attempts to retrieve the result of this future within the specified timeout.T
getOrComputeFallback(Function<@Nullable Exception,T> fallbackComputer)
Attempts to retrieve the result of this future.T
getOrComputeFallback(Function<@Nullable Exception,T> fallbackComputer, long timeout, TimeUnit unit)
Attempts to retrieve the result of this future within the specified timeout.T
getOrFallback(T fallback)
Attempts to retrieve the result of this future.T
getOrFallback(T fallback, long timeout, TimeUnit unit)
Attempts to retrieve the result of this future within the specified timeout.<U> ExtendedFuture<U>
handle(BiFunction<? super T,@Nullable Throwable,? extends U> fn)
<U> ExtendedFuture<U>
handleAsync(BiFunction<? super T,@Nullable Throwable,? extends U> fn)
<U> ExtendedFuture<U>
handleAsync(BiFunction<? super T,@Nullable Throwable,? extends U> fn, Executor executor)
boolean
isCancellableByDependents()
Returnstrue
if this future is cancellable by its dependent stages.boolean
isFailed()
Returnstrue
if thisExtendedFuture
was completed exceptionally, excluding cancellation.boolean
isIncomplete()
Returnstrue
if this future is incomplete.boolean
isInterruptible()
Returnstrue
if this future is interruptible, i.e.,cancel(true)
will result in thread interruption.boolean
isInterruptibleStages()
Returnstrue
if new stages created from this future are interruptible.boolean
isReadOnly()
Returnstrue
if this future cannot be completed programmatically through methods likecancel(boolean)
orcomplete(Object)
.boolean
isSuccess()
Returnstrue
if this future completed normally.<V> ExtendedFuture<V>
newIncompleteFuture()
T
resultNow()
This method emulates theCompletableFuture
's resultNow method introduced in Java 19.ExtendedFuture<@Nullable Void>
runAfterBoth(CompletionStage<?> other, ThrowingRunnable<?> action)
ExtendedFuture<@Nullable Void>
runAfterBoth(CompletionStage<?> other, Runnable action)
ExtendedFuture<@Nullable Void>
runAfterBothAsync(CompletionStage<?> other, ThrowingRunnable<?> action)
ExtendedFuture<@Nullable Void>
runAfterBothAsync(CompletionStage<?> other, ThrowingRunnable<?> action, Executor executor)
ExtendedFuture<@Nullable Void>
runAfterBothAsync(CompletionStage<?> other, Runnable action)
ExtendedFuture<@Nullable Void>
runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
ExtendedFuture<@Nullable Void>
runAfterEither(CompletionStage<?> other, ThrowingRunnable<?> action)
ExtendedFuture<@Nullable Void>
runAfterEither(CompletionStage<?> other, Runnable action)
ExtendedFuture<@Nullable Void>
runAfterEitherAsync(CompletionStage<?> other, ThrowingRunnable<?> action)
ExtendedFuture<@Nullable Void>
runAfterEitherAsync(CompletionStage<?> other, ThrowingRunnable<?> action, Executor executor)
ExtendedFuture<@Nullable Void>
runAfterEitherAsync(CompletionStage<?> other, Runnable action)
ExtendedFuture<@Nullable Void>
runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
static ExtendedFuture<@Nullable Void>
runAsync(ThrowingRunnable<?> runnable)
Returns anExtendedFuture
that runs the given throwing runnable asynchronously.static ExtendedFuture<@Nullable Void>
runAsync(ThrowingRunnable<?> runnable, Executor executor)
Returns anExtendedFuture
that runs the given throwing runnable asynchronously using the provided executor.static ExtendedFuture<@Nullable Void>
runAsync(Runnable runnable)
Returns anExtendedFuture
that runs the given runnable asynchronously.static ExtendedFuture<@Nullable Void>
runAsync(Runnable runnable, Executor executor)
Returns anExtendedFuture
that runs the given runnable asynchronously using the provided executor.static ExtendedFuture<@Nullable Void>
runAsyncWithDefaultExecutor(ThrowingRunnable<?> runnable, Executor defaultExecutor)
Returns anExtendedFuture
with a specified default executor that runs the given throwing runnable asynchronously.static <V> ExtendedFuture<V>
supplyAsync(ThrowingSupplier<V,?> supplier)
Returns anExtendedFuture
that runs the given throwing supplier asynchronously.static <V> ExtendedFuture<V>
supplyAsync(ThrowingSupplier<V,?> supplier, Executor executor)
Returns anExtendedFuture
that runs the given throwing supplier asynchronously using the provided executor.static <V> ExtendedFuture<V>
supplyAsync(Supplier<V> supplier)
Returns anExtendedFuture
that runs the given supplier asynchronously.static <V> ExtendedFuture<V>
supplyAsync(Supplier<V> supplier, Executor executor)
Returns anExtendedFuture
that runs the given supplier asynchronously using the provided executor.static <V> ExtendedFuture<V>
supplyAsyncWithDefaultExecutor(ThrowingSupplier<V,?> supplier, Executor defaultExecutor)
Returns anExtendedFuture
with a specified default executor that runs the given throwing supplier asynchronously.ExtendedFuture<@Nullable Void>
thenAccept(ThrowingConsumer<? super T,?> action)
ExtendedFuture<@Nullable Void>
thenAccept(Consumer<? super T> action)
ExtendedFuture<@Nullable Void>
thenAcceptAsync(ThrowingConsumer<? super T,?> action)
ExtendedFuture<@Nullable Void>
thenAcceptAsync(ThrowingConsumer<? super T,?> action, Executor executor)
ExtendedFuture<@Nullable Void>
thenAcceptAsync(Consumer<? super T> action)
ExtendedFuture<@Nullable Void>
thenAcceptAsync(Consumer<? super T> action, Executor executor)
<U> ExtendedFuture<@Nullable Void>
thenAcceptBoth(CompletionStage<? extends U> other, ThrowingBiConsumer<? super T,? super U,?> action)
<U> ExtendedFuture<@Nullable Void>
thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
<U> ExtendedFuture<@Nullable Void>
thenAcceptBothAsync(CompletionStage<? extends U> other, ThrowingBiConsumer<? super T,? super U,?> action)
<U> ExtendedFuture<@Nullable Void>
thenAcceptBothAsync(CompletionStage<? extends U> other, ThrowingBiConsumer<? super T,? super U,?> action, Executor executor)
<U> ExtendedFuture<@Nullable Void>
thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
<U> ExtendedFuture<@Nullable Void>
thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)
<U> ExtendedFuture<U>
thenApply(ThrowingFunction<? super T,? extends U,?> fn)
<U> ExtendedFuture<U>
thenApply(Function<? super T,? extends U> fn)
<U> ExtendedFuture<U>
thenApplyAsync(ThrowingFunction<? super T,? extends U,?> fn)
<U> ExtendedFuture<U>
thenApplyAsync(ThrowingFunction<? super T,? extends U,?> fn, Executor executor)
<U> ExtendedFuture<U>
thenApplyAsync(Function<? super T,? extends U> fn)
<U> ExtendedFuture<U>
thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
<U,V>
ExtendedFuture<V>thenCombine(CompletionStage<? extends U> other, ThrowingBiFunction<? super T,? super U,? extends V,?> fn)
<U,V>
ExtendedFuture<V>thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
<U,V>
ExtendedFuture<V>thenCombineAsync(CompletionStage<? extends U> other, ThrowingBiFunction<? super T,? super U,? extends V,?> fn)
<U,V>
ExtendedFuture<V>thenCombineAsync(CompletionStage<? extends U> other, ThrowingBiFunction<? super T,? super U,? extends V,?> fn, Executor executor)
<U,V>
ExtendedFuture<V>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
<U,V>
ExtendedFuture<V>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor)
<U> ExtendedFuture<U>
thenCompose(ThrowingFunction<? super T,? extends CompletionStage<U>,?> fn)
<U> ExtendedFuture<U>
thenCompose(Function<? super T,? extends CompletionStage<U>> fn)
<U> ExtendedFuture<U>
thenComposeAsync(ThrowingFunction<? super T,? extends CompletionStage<U>,?> fn)
<U> ExtendedFuture<U>
thenComposeAsync(ThrowingFunction<? super T,? extends CompletionStage<U>,?> fn, Executor executor)
<U> ExtendedFuture<U>
thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn)
<U> ExtendedFuture<U>
thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)
ExtendedFuture<@Nullable Void>
thenRun(ThrowingRunnable<?> action)
ExtendedFuture<@Nullable Void>
thenRun(Runnable action)
ExtendedFuture<@Nullable Void>
thenRunAsync(ThrowingRunnable<?> action)
ExtendedFuture<@Nullable Void>
thenRunAsync(ThrowingRunnable<?> action, Executor executor)
ExtendedFuture<@Nullable Void>
thenRunAsync(Runnable action)
ExtendedFuture<@Nullable Void>
thenRunAsync(Runnable action, Executor executor)
ExtendedFuture<T>
whenComplete(ThrowingBiConsumer<? super @Nullable T,? super @Nullable Throwable,?> action)
ExtendedFuture<T>
whenComplete(BiConsumer<? super @Nullable T,? super @Nullable Throwable> action)
ExtendedFuture<T>
whenCompleteAsync(ThrowingBiConsumer<? super @Nullable T,? super @Nullable Throwable,?> action)
ExtendedFuture<T>
whenCompleteAsync(ThrowingBiConsumer<? super @Nullable T,? super @Nullable Throwable,?> action, Executor executor)
ExtendedFuture<T>
whenCompleteAsync(BiConsumer<? super @Nullable T,? super @Nullable Throwable> action)
ExtendedFuture<T>
whenCompleteAsync(BiConsumer<? super @Nullable T,? super @Nullable Throwable> action, Executor executor)
ExtendedFuture<T>
withDefaultExecutor(Executor defaultExecutor)
Returns anExtendedFuture
that shares the result with this future, but with the specifiedExecutor
as the default for asynchronous operations of subsequent stages.ExtendedFuture<T>
withInterruptibleStages(boolean interruptibleStages)
Returns anExtendedFuture
that shares the result with this future but with the specified behavior for new stages being interruptible or not.-
Methods inherited from class java.util.concurrent.CompletableFuture
completedStage, delayedExecutor, delayedExecutor, failedStage, get, get, getNow, getNumberOfDependents, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, obtrudeException, obtrudeValue, orTimeout, toCompletableFuture, toString
-
-
-
-
Field Detail
-
cancellablePrecedingStages
protected final Collection<Future<?>> cancellablePrecedingStages
-
cancellableByDependents
protected final boolean cancellableByDependents
-
interruptibleStages
protected final boolean interruptibleStages
-
defaultExecutor
protected final Executor defaultExecutor
-
-
Method Detail
-
allOf
public static ExtendedFuture<@Nullable Void> allOf(CompletableFuture<?>... cfs)
Returns a newExtendedFuture
that completes when all of the given futures complete.- Parameters:
cfs
- the array ofCompletableFuture
instances- Returns:
- an
ExtendedFuture
that completes when all given futures complete - See Also:
CompletableFuture.allOf(CompletableFuture...)
-
anyOf
public static ExtendedFuture<@Nullable Object> anyOf(CompletableFuture<?>... cfs)
Returns a newExtendedFuture
that completes when any of the given futures complete.- Parameters:
cfs
- the array ofCompletableFuture
instances- Returns:
- an
ExtendedFuture
that completes when any given future completes - See Also:
CompletableFuture.anyOf(CompletableFuture...)
-
builder
@NonNullByDefault({}) public static <V> ExtendedFuture.Builder<V> builder(Class<V> targetType)
Creates a newExtendedFuture.Builder
for constructing anExtendedFuture
.- Type Parameters:
V
- the result type of the future- Returns:
- a new
ExtendedFuture.Builder
instance
-
completedFuture
public static <V> ExtendedFuture<V> completedFuture(V value)
Returns a completedExtendedFuture
with the given value.- Type Parameters:
V
- the result type of the future- Parameters:
value
- the value to complete the future with- Returns:
- a completed
ExtendedFuture
-
failedFuture
public static <V> ExtendedFuture<V> failedFuture(Throwable ex)
Returns a completedExtendedFuture
that has completed exceptionally with the given exception.- Type Parameters:
V
- the result type of the future- Parameters:
ex
- the exception to complete the future with- Returns:
- a completed
ExtendedFuture
that completed exceptionally
-
from
public static <V> ExtendedFuture<V> from(CompletableFuture<V> source)
Wraps a givenCompletableFuture
into anExtendedFuture
. If the given future is already an instance ofExtendedFuture
withisCancellableByDependents()
set tofalse
, it is returned as-is.- Type Parameters:
V
- the result type of the future- Parameters:
source
- theCompletableFuture
to wrap- Returns:
- an
ExtendedFuture
wrapping the given future
-
runAsync
public static ExtendedFuture<@Nullable Void> runAsync(Runnable runnable)
Returns anExtendedFuture
that runs the given runnable asynchronously.- Parameters:
runnable
- theRunnable
to execute- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
runAsync
public static ExtendedFuture<@Nullable Void> runAsync(Runnable runnable, Executor executor)
Returns anExtendedFuture
that runs the given runnable asynchronously using the provided executor.- Parameters:
runnable
- theRunnable
to executeexecutor
- theExecutor
to use for execution- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
runAsync
public static ExtendedFuture<@Nullable Void> runAsync(ThrowingRunnable<?> runnable)
Returns anExtendedFuture
that runs the given throwing runnable asynchronously.- Parameters:
runnable
- theThrowingRunnable
to execute- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
runAsync
public static ExtendedFuture<@Nullable Void> runAsync(ThrowingRunnable<?> runnable, Executor executor)
Returns anExtendedFuture
that runs the given throwing runnable asynchronously using the provided executor.- Parameters:
runnable
- theThrowingRunnable
to executeexecutor
- theExecutor
to use for execution- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
runAsyncWithDefaultExecutor
public static ExtendedFuture<@Nullable Void> runAsyncWithDefaultExecutor(ThrowingRunnable<?> runnable, Executor defaultExecutor)
Returns anExtendedFuture
with a specified default executor that runs the given throwing runnable asynchronously.- Parameters:
runnable
- theThrowingRunnable
to executedefaultExecutor
- the defaultExecutor
to use for execution- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
supplyAsync
public static <V> ExtendedFuture<V> supplyAsync(Supplier<V> supplier)
Returns anExtendedFuture
that runs the given supplier asynchronously.- Type Parameters:
V
- the result type of the future- Parameters:
supplier
- theSupplier
to execute- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
supplyAsync
public static <V> ExtendedFuture<V> supplyAsync(Supplier<V> supplier, Executor executor)
Returns anExtendedFuture
that runs the given supplier asynchronously using the provided executor.- Type Parameters:
V
- the result type of the future- Parameters:
supplier
- theSupplier
to executeexecutor
- theExecutor
to use for execution- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
supplyAsync
public static <V> ExtendedFuture<V> supplyAsync(ThrowingSupplier<V,?> supplier)
Returns anExtendedFuture
that runs the given throwing supplier asynchronously.- Type Parameters:
V
- the result type of the future- Parameters:
supplier
- theThrowingSupplier
to execute- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
supplyAsync
public static <V> ExtendedFuture<V> supplyAsync(ThrowingSupplier<V,?> supplier, Executor executor)
Returns anExtendedFuture
that runs the given throwing supplier asynchronously using the provided executor.- Type Parameters:
V
- the result type of the future- Parameters:
supplier
- theThrowingSupplier
to executeexecutor
- theExecutor
to use for execution- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
supplyAsyncWithDefaultExecutor
public static <V> ExtendedFuture<V> supplyAsyncWithDefaultExecutor(ThrowingSupplier<V,?> supplier, Executor defaultExecutor)
Returns anExtendedFuture
with a specified default executor that runs the given throwing supplier asynchronously.- Type Parameters:
V
- the result type of the future- Parameters:
supplier
- theThrowingSupplier
to executedefaultExecutor
- the defaultExecutor
to use for execution- Returns:
- an
ExtendedFuture
representing the asynchronous computation
-
acceptEither
public ExtendedFuture<@Nullable Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEither
in interfaceCompletionStage<T>
- Overrides:
acceptEither
in classCompletableFuture<T>
-
acceptEither
public ExtendedFuture<@Nullable Void> acceptEither(CompletionStage<? extends T> other, ThrowingConsumer<? super T,?> action)
-
acceptEitherAsync
public ExtendedFuture<@Nullable Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<T>
- Overrides:
acceptEitherAsync
in classCompletableFuture<T>
-
acceptEitherAsync
public ExtendedFuture<@Nullable Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<T>
- Overrides:
acceptEitherAsync
in classCompletableFuture<T>
-
acceptEitherAsync
public ExtendedFuture<@Nullable Void> acceptEitherAsync(CompletionStage<? extends T> other, ThrowingConsumer<? super T,?> action)
-
acceptEitherAsync
public ExtendedFuture<@Nullable Void> acceptEitherAsync(CompletionStage<? extends T> other, ThrowingConsumer<? super T,?> action, Executor executor)
-
addTo
public ExtendedFuture<T> addTo(Consumer<Future<T>> consumer)
Passes this future to the givenConsumer
.- Parameters:
consumer
- the consumer to which this future is added- Returns:
- this
ExtendedFuture
instance for method chaining
-
addTo
public ExtendedFuture<T> addTo(Futures.Combiner<T> combiner)
Adds this future to the givenFutures.Combiner
.- Parameters:
combiner
- the future combiner to which this future is added- Returns:
- this
ExtendedFuture
instance for method chaining
-
applyToEither
public <U> ExtendedFuture<U> applyToEither(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEither
in interfaceCompletionStage<T>
- Overrides:
applyToEither
in classCompletableFuture<T>
-
applyToEither
public <U> ExtendedFuture<U> applyToEither(CompletionStage<? extends T> other, ThrowingFunction<? super T,U,?> fn)
-
applyToEitherAsync
public <U> ExtendedFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<T>
- Overrides:
applyToEitherAsync
in classCompletableFuture<T>
-
applyToEitherAsync
public <U> ExtendedFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<T>
- Overrides:
applyToEitherAsync
in classCompletableFuture<T>
-
applyToEitherAsync
public <U> ExtendedFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, ThrowingFunction<? super T,U,?> fn)
-
applyToEitherAsync
public <U> ExtendedFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, ThrowingFunction<? super T,U,?> fn, Executor executor)
-
asCancellableByDependents
public ExtendedFuture<T> asCancellableByDependents(boolean isCancellableByDependents)
Returns anExtendedFuture
that shares the result with this future but allows control over whether cancellation of dependent stages cancels this future.If the requested cancellation behavior matches the current one, this instance is returned. Otherwise, a new
ExtendedFuture
is created with the updated behavior.Any newly created dependent stages will inherit this cancellation behavior.
- Parameters:
isCancellableByDependents
-true
if cancellation of a dependent stage should also cancel this future and its preceding stages;false
if cancellation of dependent stages should not affect this future.- Returns:
- a new
ExtendedFuture
with the specified cancellation behavior, or this instance if the behavior remains unchanged.
-
asNonInterruptible
public ExtendedFuture<T> asNonInterruptible()
Returns anExtendedFuture
that shares the result with this future but ensures that this future cannot be interrupted, i.e., callingcancel(true)
will not result in a thread interruption.If the future is already non-interruptible, this instance is returned.
- Returns:
- a new
ExtendedFuture
that is non-interruptible, or this instance if it is already non-interruptible.
-
asReadOnly
public ExtendedFuture<T> asReadOnly(ExtendedFuture.ReadOnlyMode readOnlyMode)
Creates a read-only view of thisExtendedFuture
.The returned future is backed by this future, allowing only read operations such as
CompletableFuture.get()
,CompletableFuture.join()
, and other non-mutating methods. Any attempt to invoke mutating operations such ascancel(boolean)
,complete(Object)
,completeExceptionally(Throwable)
, orCompletableFuture.obtrudeValue(Object)
will result in anUnsupportedOperationException
or be silently ignored, depending on the specifiedExtendedFuture.ReadOnlyMode
.- Parameters:
readOnlyMode
- the behavior when a mutating operation is attempted:ExtendedFuture.ReadOnlyMode.THROW_ON_MUTATION
to throwUnsupportedOperationException
, orExtendedFuture.ReadOnlyMode.IGNORE_MUTATION
to silently ignore mutation attempts.- Returns:
- a read-only
ExtendedFuture
that is backed by the original future
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
If the preceding stage has
isCancellableByDependents()
set, the cancellation will also propagate to the preceding stage.- Specified by:
cancel
in interfaceFuture<T>
- Overrides:
cancel
in classCompletableFuture<T>
- Parameters:
mayInterruptIfRunning
-true
if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete.- Returns:
true
if this task was successfully cancelled;false
if the task could not be cancelled, typically because it has already completed.
-
complete
public boolean complete(T value)
Completes this future with the given value if not already completed.- Overrides:
complete
in classCompletableFuture<T>
- Parameters:
value
- the value to complete this future with- Returns:
true
if this invocation caused this future to transition to a completed state, otherwisefalse
-
completeAsync
public ExtendedFuture<T> completeAsync(Supplier<? extends T> supplier)
Completes this future with the result of the given supplier function, running it asynchronously using the default executor.- Overrides:
completeAsync
in classCompletableFuture<T>
- Parameters:
supplier
- the supplier function to produce the completion value- Returns:
- this
ExtendedFuture
for method chaining
-
completeAsync
public ExtendedFuture<T> completeAsync(Supplier<? extends T> supplier, Executor executor)
Completes this future with the result of the given supplier function, running it asynchronously using the specified executor.- Overrides:
completeAsync
in classCompletableFuture<T>
- Parameters:
supplier
- the supplier function to produce the completion valueexecutor
- the executor to use for asynchronous execution- Returns:
- this
ExtendedFuture
for method chaining
-
completeAsync
public ExtendedFuture<T> completeAsync(ThrowingSupplier<? extends T,?> supplier)
Completes this future with the result of the given throwing supplier function, running it asynchronously using the default executor.- Parameters:
supplier
- the throwing supplier function to produce the completion value- Returns:
- this
ExtendedFuture
for method chaining
-
completeAsync
public ExtendedFuture<T> completeAsync(ThrowingSupplier<? extends T,?> supplier, Executor executor)
Completes this future with the result of the given throwing supplier function, running it asynchronously using the specified executor.- Parameters:
supplier
- the throwing supplier function to produce the completion valueexecutor
- the executor to use for asynchronous execution- Returns:
- this
ExtendedFuture
for method chaining
-
completeExceptionally
public boolean completeExceptionally(Throwable ex)
Completes this future exceptionally with the given exception if not already completed.- Overrides:
completeExceptionally
in classCompletableFuture<T>
- Parameters:
ex
- the exception to complete this future with- Returns:
true
if this invocation caused this future to transition to a completed state, otherwisefalse
-
completeOnTimeout
public ExtendedFuture<T> completeOnTimeout(T value, long timeout, TimeUnit unit)
- Overrides:
completeOnTimeout
in classCompletableFuture<T>
-
completeWith
public ExtendedFuture<T> completeWith(CompletableFuture<? extends T> future)
Completes thisExtendedFuture
when the providedCompletableFuture
finishes, with either its result or its exception.- Parameters:
future
- theCompletableFuture
whose completion will trigger this future's completion- Returns:
- this
ExtendedFuture
for chaining
-
copy
public ExtendedFuture<T> copy()
- Overrides:
copy
in classCompletableFuture<T>
-
defaultExecutor
public Executor defaultExecutor()
- Overrides:
defaultExecutor
in classCompletableFuture<T>
-
exceptionally
public ExtendedFuture<T> exceptionally(Function<Throwable,? extends T> fn)
- Specified by:
exceptionally
in interfaceCompletionStage<T>
- Overrides:
exceptionally
in classCompletableFuture<T>
-
exceptionally
public ExtendedFuture<T> exceptionally(ThrowingFunction<Throwable,? extends T,?> fn)
-
exceptionallyAsync
public ExtendedFuture<T> exceptionallyAsync(Function<Throwable,? extends T> fn)
This method emulates theCompletableFuture
's exceptionallyAsync method introduced in Java 12.
-
exceptionallyAsync
public ExtendedFuture<T> exceptionallyAsync(Function<Throwable,? extends T> fn, Executor executor)
This method emulates theCompletableFuture
's exceptionallyAsync method introduced in Java 12.
-
exceptionallyAsync
public ExtendedFuture<T> exceptionallyAsync(ThrowingFunction<Throwable,? extends T,?> fn)
-
exceptionallyAsync
public ExtendedFuture<T> exceptionallyAsync(ThrowingFunction<Throwable,? extends T,?> fn, Executor executor)
-
exceptionallyCompose
public ExtendedFuture<T> exceptionallyCompose(Function<Throwable,? extends CompletionStage<T>> fn)
This method emulates theCompletableFuture
's exceptionallyCompose method introduced in Java 12.
-
exceptionallyCompose
public ExtendedFuture<T> exceptionallyCompose(ThrowingFunction<Throwable,? extends CompletionStage<T>,?> fn)
-
exceptionallyComposeAsync
public ExtendedFuture<T> exceptionallyComposeAsync(Function<Throwable,? extends CompletionStage<T>> fn)
This method emulates theCompletableFuture
's exceptionallyComposeAsync method introduced in Java 12.
-
exceptionallyComposeAsync
public ExtendedFuture<T> exceptionallyComposeAsync(Function<Throwable,? extends CompletionStage<T>> fn, Executor executor)
This method emulates theCompletableFuture
's exceptionallyComposeAsync method introduced in Java 12.
-
exceptionallyComposeAsync
public ExtendedFuture<T> exceptionallyComposeAsync(ThrowingFunction<Throwable,? extends CompletionStage<T>,?> fn)
-
exceptionallyComposeAsync
public ExtendedFuture<T> exceptionallyComposeAsync(ThrowingFunction<Throwable,? extends CompletionStage<T>,?> fn, Executor executor)
-
exceptionNow
public Throwable exceptionNow()
This method emulates theCompletableFuture
's exceptionNow method introduced in Java 19.- Throws:
IllegalStateException
- if the task has not yet completed, completed normally, or was cancelled
-
forwardCancellation
public ExtendedFuture<T> forwardCancellation(@Nullable Future<?> to)
Propagates the cancellation of thisExtendedFuture
to anotherFuture
.If this
ExtendedFuture
is cancelled, theto
future will be cancelled too.- Parameters:
to
- theFuture
instance that should be cancelled if this future is cancelled- Returns:
- this
ExtendedFuture
for method chaining
-
forwardCancellation
public ExtendedFuture<T> forwardCancellation(@NonNullByDefault({}) Future<?> @Nullable ... to)
Propagates the cancellation of thisExtendedFuture
to otherFuture
s.If this
ExtendedFuture
is cancelled, all futures in the providedto
array will be cancelled too.- Parameters:
to
- the array ofFuture
instances that should be cancelled if this future is cancelled- Returns:
- this
ExtendedFuture
for method chaining
-
forwardCancellationTo
public ExtendedFuture<T> forwardCancellationTo(@Nullable Collection<? extends @Nullable Future<?>> to)
Propagates the cancellation of thisExtendedFuture
to otherFuture
s.If this
ExtendedFuture
is cancelled, all futures in the providedto
collection will be cancelled too.- Parameters:
to
- the collection ofFuture
instances that should be cancelled if this future is cancelled- Returns:
- this
ExtendedFuture
for method chaining
-
getNowOrComputeFallback
public T getNowOrComputeFallback(BiFunction<Future<T>,@Nullable Exception,T> fallbackComputer)
Returns the result of this future if it is already completed, or the value provided byfallbackComputer
if the future is incomplete, cancelled or failed.- Returns:
- the result of the future if completed normally, otherwise the value computed by
fallbackComputer
-
getNowOrComputeFallback
public T getNowOrComputeFallback(Function<@Nullable Exception,T> fallbackComputer)
Returns the result of this future if it is already completed, or the value provided byfallbackComputer
if the future is incomplete, cancelled or failed.- Returns:
- the result of the future if completed normally, otherwise the value computed by
fallbackComputer
-
getNowOrFallback
public T getNowOrFallback(T fallback)
Returns the result of this future if it is already completed, or the specifiedfallback
if the future is incomplete, cancelled or failed.- Returns:
- the result of the future if completed normally, otherwise
fallback
-
getOptional
public Optional<T> getOptional()
Attempts to retrieve the result this future within the specified timeout.
-
getOptional
public Optional<T> getOptional(long timeout, TimeUnit unit)
Attempts to retrieve the result this future within the specified timeout.
-
getOrComputeFallback
public T getOrComputeFallback(BiFunction<Future<T>,@Nullable Exception,T> fallbackComputer)
Attempts to retrieve the result of this future.- Returns:
- the result of the future if completed normally, otherwise the value computed by
fallbackComputer
-
getOrComputeFallback
public T getOrComputeFallback(BiFunction<Future<T>,@Nullable Exception,T> fallbackComputer, long timeout, TimeUnit unit)
Attempts to retrieve the result of this future within the specified timeout.- Returns:
- the result of the future if completed normally within given timeout, otherwise the value computed by
fallbackComputer
-
getOrComputeFallback
public T getOrComputeFallback(Function<@Nullable Exception,T> fallbackComputer)
Attempts to retrieve the result of this future.- Returns:
- the result of the future if completed normally, otherwise the value computed by
fallbackComputer
-
getOrComputeFallback
public T getOrComputeFallback(Function<@Nullable Exception,T> fallbackComputer, long timeout, TimeUnit unit)
Attempts to retrieve the result of this future within the specified timeout.- Returns:
- the result of the future if completed normally within given timeout, otherwise the value computed by
fallbackComputer
-
getOrFallback
public T getOrFallback(T fallback)
Attempts to retrieve the result of this future.- Returns:
- the result of the future if completed normally, otherwise
fallback
-
getOrFallback
public T getOrFallback(T fallback, long timeout, TimeUnit unit)
Attempts to retrieve the result of this future within the specified timeout.- Returns:
- the result of the future if completed normally within given timeout, otherwise
fallback
-
handle
public <U> ExtendedFuture<U> handle(BiFunction<? super T,@Nullable Throwable,? extends U> fn)
- Specified by:
handle
in interfaceCompletionStage<T>
- Overrides:
handle
in classCompletableFuture<T>
-
handleAsync
public <U> ExtendedFuture<U> handleAsync(BiFunction<? super T,@Nullable Throwable,? extends U> fn)
- Specified by:
handleAsync
in interfaceCompletionStage<T>
- Overrides:
handleAsync
in classCompletableFuture<T>
-
handleAsync
public <U> ExtendedFuture<U> handleAsync(BiFunction<? super T,@Nullable Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsync
in interfaceCompletionStage<T>
- Overrides:
handleAsync
in classCompletableFuture<T>
-
isCancellableByDependents
public boolean isCancellableByDependents()
Returnstrue
if this future is cancellable by its dependent stages. Iftrue
, cancellation of a dependent stage will also cancel this future and any preceding stages. Iffalse
, cancellation of dependent stages will not affect this future.- Returns:
true
if this future is cancellable by dependents,false
otherwise
-
isFailed
public boolean isFailed()
Returnstrue
if thisExtendedFuture
was completed exceptionally, excluding cancellation.- Returns:
true
if the future completed exceptionally but was not cancelled
-
isIncomplete
public boolean isIncomplete()
Returnstrue
if this future is incomplete.- Returns:
true
if this future is incomplete,false
otherwise
-
isInterruptible
public boolean isInterruptible()
Returnstrue
if this future is interruptible, i.e.,cancel(true)
will result in thread interruption.- Returns:
true
if this future is interruptible,false
otherwise
-
isInterruptibleStages
public boolean isInterruptibleStages()
Returnstrue
if new stages created from this future are interruptible.- Returns:
true
if new stages are interruptible,false
otherwise
-
isReadOnly
public boolean isReadOnly()
Returnstrue
if this future cannot be completed programmatically through methods likecancel(boolean)
orcomplete(Object)
.- Returns:
true
if this future is read-only,false
otherwise
-
isSuccess
public boolean isSuccess()
Returnstrue
if this future completed normally.- Returns:
true
if this future completed normally,false
otherwise
-
newIncompleteFuture
public <V> ExtendedFuture<V> newIncompleteFuture()
- Overrides:
newIncompleteFuture
in classCompletableFuture<T>
-
resultNow
public T resultNow()
This method emulates theCompletableFuture
's resultNow method introduced in Java 19.- Returns:
- the computed result
- Throws:
IllegalStateException
- if the task has not yet completed or failed
-
runAfterBoth
public ExtendedFuture<@Nullable Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBoth
in interfaceCompletionStage<T>
- Overrides:
runAfterBoth
in classCompletableFuture<T>
-
runAfterBoth
public ExtendedFuture<@Nullable Void> runAfterBoth(CompletionStage<?> other, ThrowingRunnable<?> action)
-
runAfterBothAsync
public ExtendedFuture<@Nullable Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterBothAsync
in classCompletableFuture<T>
-
runAfterBothAsync
public ExtendedFuture<@Nullable Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterBothAsync
in classCompletableFuture<T>
-
runAfterBothAsync
public ExtendedFuture<@Nullable Void> runAfterBothAsync(CompletionStage<?> other, ThrowingRunnable<?> action)
-
runAfterBothAsync
public ExtendedFuture<@Nullable Void> runAfterBothAsync(CompletionStage<?> other, ThrowingRunnable<?> action, Executor executor)
-
runAfterEither
public ExtendedFuture<@Nullable Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEither
in interfaceCompletionStage<T>
- Overrides:
runAfterEither
in classCompletableFuture<T>
-
runAfterEither
public ExtendedFuture<@Nullable Void> runAfterEither(CompletionStage<?> other, ThrowingRunnable<?> action)
-
runAfterEitherAsync
public ExtendedFuture<@Nullable Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterEitherAsync
in classCompletableFuture<T>
-
runAfterEitherAsync
public ExtendedFuture<@Nullable Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterEitherAsync
in classCompletableFuture<T>
-
runAfterEitherAsync
public ExtendedFuture<@Nullable Void> runAfterEitherAsync(CompletionStage<?> other, ThrowingRunnable<?> action)
-
runAfterEitherAsync
public ExtendedFuture<@Nullable Void> runAfterEitherAsync(CompletionStage<?> other, ThrowingRunnable<?> action, Executor executor)
-
thenAccept
public ExtendedFuture<@Nullable Void> thenAccept(Consumer<? super T> action)
- Specified by:
thenAccept
in interfaceCompletionStage<T>
- Overrides:
thenAccept
in classCompletableFuture<T>
-
thenAccept
public ExtendedFuture<@Nullable Void> thenAccept(ThrowingConsumer<? super T,?> action)
-
thenAcceptAsync
public ExtendedFuture<@Nullable Void> thenAcceptAsync(Consumer<? super T> action)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptAsync
in classCompletableFuture<T>
-
thenAcceptAsync
public ExtendedFuture<@Nullable Void> thenAcceptAsync(Consumer<? super T> action, Executor executor)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptAsync
in classCompletableFuture<T>
-
thenAcceptAsync
public ExtendedFuture<@Nullable Void> thenAcceptAsync(ThrowingConsumer<? super T,?> action)
-
thenAcceptAsync
public ExtendedFuture<@Nullable Void> thenAcceptAsync(ThrowingConsumer<? super T,?> action, Executor executor)
-
thenAcceptBoth
public <U> ExtendedFuture<@Nullable Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBoth
in interfaceCompletionStage<T>
- Overrides:
thenAcceptBoth
in classCompletableFuture<T>
-
thenAcceptBoth
public <U> ExtendedFuture<@Nullable Void> thenAcceptBoth(CompletionStage<? extends U> other, ThrowingBiConsumer<? super T,? super U,?> action)
-
thenAcceptBothAsync
public <U> ExtendedFuture<@Nullable Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptBothAsync
in classCompletableFuture<T>
-
thenAcceptBothAsync
public <U> ExtendedFuture<@Nullable Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptBothAsync
in classCompletableFuture<T>
-
thenAcceptBothAsync
public <U> ExtendedFuture<@Nullable Void> thenAcceptBothAsync(CompletionStage<? extends U> other, ThrowingBiConsumer<? super T,? super U,?> action)
-
thenAcceptBothAsync
public <U> ExtendedFuture<@Nullable Void> thenAcceptBothAsync(CompletionStage<? extends U> other, ThrowingBiConsumer<? super T,? super U,?> action, Executor executor)
-
thenApply
public <U> ExtendedFuture<U> thenApply(Function<? super T,? extends U> fn)
- Specified by:
thenApply
in interfaceCompletionStage<T>
- Overrides:
thenApply
in classCompletableFuture<T>
-
thenApply
public <U> ExtendedFuture<U> thenApply(ThrowingFunction<? super T,? extends U,?> fn)
-
thenApplyAsync
public <U> ExtendedFuture<U> thenApplyAsync(Function<? super T,? extends U> fn)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<T>
- Overrides:
thenApplyAsync
in classCompletableFuture<T>
-
thenApplyAsync
public <U> ExtendedFuture<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<T>
- Overrides:
thenApplyAsync
in classCompletableFuture<T>
-
thenApplyAsync
public <U> ExtendedFuture<U> thenApplyAsync(ThrowingFunction<? super T,? extends U,?> fn)
-
thenApplyAsync
public <U> ExtendedFuture<U> thenApplyAsync(ThrowingFunction<? super T,? extends U,?> fn, Executor executor)
-
thenCombine
public <U,V> ExtendedFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombine
in interfaceCompletionStage<T>
- Overrides:
thenCombine
in classCompletableFuture<T>
-
thenCombine
public <U,V> ExtendedFuture<V> thenCombine(CompletionStage<? extends U> other, ThrowingBiFunction<? super T,? super U,? extends V,?> fn)
-
thenCombineAsync
public <U,V> ExtendedFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombineAsync
in interfaceCompletionStage<T>
- Overrides:
thenCombineAsync
in classCompletableFuture<T>
-
thenCombineAsync
public <U,V> ExtendedFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor)
- Specified by:
thenCombineAsync
in interfaceCompletionStage<T>
- Overrides:
thenCombineAsync
in classCompletableFuture<T>
-
thenCombineAsync
public <U,V> ExtendedFuture<V> thenCombineAsync(CompletionStage<? extends U> other, ThrowingBiFunction<? super T,? super U,? extends V,?> fn)
-
thenCombineAsync
public <U,V> ExtendedFuture<V> thenCombineAsync(CompletionStage<? extends U> other, ThrowingBiFunction<? super T,? super U,? extends V,?> fn, Executor executor)
-
thenCompose
public <U> ExtendedFuture<U> thenCompose(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenCompose
in interfaceCompletionStage<T>
- Overrides:
thenCompose
in classCompletableFuture<T>
-
thenCompose
public <U> ExtendedFuture<U> thenCompose(ThrowingFunction<? super T,? extends CompletionStage<U>,?> fn)
-
thenComposeAsync
public <U> ExtendedFuture<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<T>
- Overrides:
thenComposeAsync
in classCompletableFuture<T>
-
thenComposeAsync
public <U> ExtendedFuture<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<T>
- Overrides:
thenComposeAsync
in classCompletableFuture<T>
-
thenComposeAsync
public <U> ExtendedFuture<U> thenComposeAsync(ThrowingFunction<? super T,? extends CompletionStage<U>,?> fn)
-
thenComposeAsync
public <U> ExtendedFuture<U> thenComposeAsync(ThrowingFunction<? super T,? extends CompletionStage<U>,?> fn, Executor executor)
-
thenRun
public ExtendedFuture<@Nullable Void> thenRun(Runnable action)
- Specified by:
thenRun
in interfaceCompletionStage<T>
- Overrides:
thenRun
in classCompletableFuture<T>
-
thenRun
public ExtendedFuture<@Nullable Void> thenRun(ThrowingRunnable<?> action)
-
thenRunAsync
public ExtendedFuture<@Nullable Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsync
in interfaceCompletionStage<T>
- Overrides:
thenRunAsync
in classCompletableFuture<T>
-
thenRunAsync
public ExtendedFuture<@Nullable Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsync
in interfaceCompletionStage<T>
- Overrides:
thenRunAsync
in classCompletableFuture<T>
-
thenRunAsync
public ExtendedFuture<@Nullable Void> thenRunAsync(ThrowingRunnable<?> action)
-
thenRunAsync
public ExtendedFuture<@Nullable Void> thenRunAsync(ThrowingRunnable<?> action, Executor executor)
-
whenComplete
public ExtendedFuture<T> whenComplete(BiConsumer<? super @Nullable T,? super @Nullable Throwable> action)
- Specified by:
whenComplete
in interfaceCompletionStage<T>
- Overrides:
whenComplete
in classCompletableFuture<T>
-
whenComplete
public ExtendedFuture<T> whenComplete(ThrowingBiConsumer<? super @Nullable T,? super @Nullable Throwable,?> action)
-
whenCompleteAsync
public ExtendedFuture<T> whenCompleteAsync(BiConsumer<? super @Nullable T,? super @Nullable Throwable> action)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<T>
- Overrides:
whenCompleteAsync
in classCompletableFuture<T>
-
whenCompleteAsync
public ExtendedFuture<T> whenCompleteAsync(BiConsumer<? super @Nullable T,? super @Nullable Throwable> action, Executor executor)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<T>
- Overrides:
whenCompleteAsync
in classCompletableFuture<T>
-
whenCompleteAsync
public ExtendedFuture<T> whenCompleteAsync(ThrowingBiConsumer<? super @Nullable T,? super @Nullable Throwable,?> action)
-
whenCompleteAsync
public ExtendedFuture<T> whenCompleteAsync(ThrowingBiConsumer<? super @Nullable T,? super @Nullable Throwable,?> action, Executor executor)
-
withDefaultExecutor
public ExtendedFuture<T> withDefaultExecutor(Executor defaultExecutor)
Returns anExtendedFuture
that shares the result with this future, but with the specifiedExecutor
as the default for asynchronous operations of subsequent stages.- Parameters:
defaultExecutor
- the defaultExecutor
for async tasks, must not benull
- Returns:
- a new
ExtendedFuture
with the specified executor, orthis
if the executor is unchanged
-
withInterruptibleStages
public ExtendedFuture<T> withInterruptibleStages(boolean interruptibleStages)
Returns anExtendedFuture
that shares the result with this future but with the specified behavior for new stages being interruptible or not.If the requested interruptibility behavior matches the current one, this instance is returned.
- Parameters:
interruptibleStages
-true
if new stages should be interruptible,false
otherwise- Returns:
- a new
ExtendedFuture
with the specified interruptibility behavior for new stages, or this instance if the behavior remains unchanged
-
-