Class Cffu<T>
- All Implemented Interfaces:
CompletionStage<T>,Future<T>
Cffu is the equivalent class to CompletableFuture,
contains the equivalent instance methods of CompletionStage and CompletableFuture.
The methods that equivalent to static factory methods of CompletableFuture
is in CffuFactory class.
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Method Summary
Modifier and TypeMethodDescriptionacceptEither(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action.acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied action.acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action.acceptEitherSuccess(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action.acceptEitherSuccessAsync(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied action.acceptEitherSuccessAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action.allTupleOf(CompletionStage<? extends T2> cf2) This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage), providing this method is convenient for method chaining.allTupleOf(CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3) This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.allTupleOf(CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4) This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.allTupleOf(CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4, CompletionStage<? extends T5> cf5) This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.allTupleOfFastFail(CompletionStage<? extends T2> cf2) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage), providing this method is convenient for method chaining.allTupleOfFastFail(CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.allTupleOfFastFail(CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.allTupleOfFastFail(CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4, CompletionStage<? extends T5> cf5) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.<U> Cffu<U> applyToEither(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function.<U> Cffu<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied function.<U> Cffu<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function.<U> Cffu<U> applyToEitherSuccess(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function.<U> Cffu<U> applyToEitherSuccessAsync(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied function.<U> Cffu<U> applyToEitherSuccessAsync(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function.booleancancel(boolean mayInterruptIfRunning) If not already completed, completes this Cffu with aCancellationException.Returns theCffuFactoryof this Cffu.Returns the computation state(CffuState), this method is equivalent toCompletableFuture.state()with java version compatibility logic, so you can invoke in oldjava 18-.Returns the underlying CompletableFuture.booleanIf not already completed, sets the value returned byget()and related methods to the given value.completeAsync(Supplier<? extends T> supplier) Completes this Cffu with the result of the given Supplier function invoked from an asynchronous task usingdefaultExecutor().completeAsync(Supplier<? extends T> supplier, Executor executor) Completes this Cffu with the result of the given Supplier function invoked from an asynchronous task using the given executor.booleanIf not already completed, causes invocations ofget()and related methods to throw the given exception.completeOnTimeout(T value, long timeout, TimeUnit unit) Completes this Cffu with the given value if not otherwise completed before the given timeout.copy()Returns a new Cffu that is completed normally with the same value as this Cffu when it completes normally.Returns the default Executor used for async methods that do not specify an Executor.exceptionally(Function<Throwable, ? extends T> fn) Returns a new Cffu that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function.exceptionallyAsync(Function<Throwable, ? extends T> fn) Returns a new Cffu that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, usingdefaultExecutor().exceptionallyAsync(Function<Throwable, ? extends T> fn, Executor executor) Returns a new Cffu that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, using the supplied Executor.exceptionallyCompose(Function<Throwable, ? extends CompletionStage<T>> fn) Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception.exceptionallyComposeAsync(Function<Throwable, ? extends CompletionStage<T>> fn) Returns a new Cffu that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, usingdefaultExecutor().exceptionallyComposeAsync(Function<Throwable, ? extends CompletionStage<T>> fn, Executor executor) Returns a new Cffu that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, using the supplied Executor.Returns the exception thrown by the task, without waiting.booleanReturnsforbidObtrudeMethodsor not.get()Waits if necessary for the computation to complete, and then retrieves its result.Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.intReturns the estimated number of Cffus whose completions are awaiting completion of this Cffu.<U> Cffu<U> handle(BiFunction<? super T, Throwable, ? extends U> fn) Returns a new Cffu that, when this cffu completes either normally or exceptionally, is executed with this cffu's result and exception as arguments to the supplied function.<U> Cffu<U> handleAsync(BiFunction<? super T, Throwable, ? extends U> fn) Returns a new Cffu that, when this cffu completes either normally or exceptionally, is executed usingdefaultExecutor(), with this cffu's result and exception as arguments to the supplied function.<U> Cffu<U> handleAsync(BiFunction<? super T, Throwable, ? extends U> fn, Executor executor) Returns a new Cffu that, when this cffu completes either normally or exceptionally, is executed using the supplied executor, with this cffu's result and exception as arguments to the supplied function.booleanReturnstrueif this Cffu was cancelled before it completed normally.booleanReturnstrueif this Cffu completed exceptionally, in any way.booleanisDone()Returnstrueif this task completed.booleanReturns whether is aminimal stageor not.join()Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally.Waits if necessary for at most the given time for the computation to complete, and then retrieves its result value when complete, or throws an (unchecked) exception if completed exceptionally.Returns a new CompletionStage that is completed normally with the same value as this CompletableFuture when it completes normally, and cannot be independently completed or otherwise used in ways not defined by the methods of interfaceCompletionStage.<U> Cffu<U> Returns a new incomplete Cffu with CompletableFuture of the type to be returned by a CompletionStage method.voidForcibly causes subsequent invocations of methodget()and related methods to throw the given exception, whether or not already completed.voidobtrudeValue(T value) Forcibly sets or resets the value subsequently returned by methodget()and related methods, whether or not already completed.Exceptionally completes this Cffu with aTimeoutExceptionif not otherwise completed before the given timeout.peek(BiConsumer<? super T, ? super Throwable> action) Peeks the result by executing the given action when this cffu completes, returns this cffu.peekAsync(BiConsumer<? super T, ? super Throwable> action) Peeks the result by executing the given action when this cffu completes, executes the given action usingdefaultExecutor(), returns this cffu.peekAsync(BiConsumer<? super T, ? super Throwable> action, Executor executor) Peeks the result by executing the given action when this cffu completes, that executes the given action using the supplied Executor when this cffu completes, returns this cffu.resetCffuFactory(CffuFactory cffuFactory) Returns a new Cffu with given CffuFactory(contained configuration) that is completed normally with the same value as this Cffu when it completes normally.Returns the computed result, without waiting.runAfterBoth(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action.runAfterBothAsync(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action usingdefaultExecutor().runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action using the supplied executor.runAfterBothFastFail(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action.runAfterBothFastFailAsync(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action usingdefaultExecutor().runAfterBothFastFailAsync(CompletionStage<?> other, Runnable action, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action using the supplied executor.runAfterEither(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action.runAfterEitherAsync(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action usingdefaultExecutor().runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action using the supplied executor.runAfterEitherSuccess(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action.runAfterEitherSuccessAsync(CompletionStage<?> other, Runnable action) Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action usingdefaultExecutor().runAfterEitherSuccessAsync(CompletionStage<?> other, Runnable action, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action using the supplied executor.state()Returns the computation state, this method contains NO java version compatibility logic, if you need this function in oldjava 18-, usecffuState()instead.thenAccept(Consumer<? super T> action) Returns a new Cffu that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action.thenAcceptAsync(Consumer<? super T> action) Returns a new Cffu that, when this stage completes normally, is executed usingdefaultExecutor(), with this stage's result as the argument to the supplied action.thenAcceptAsync(Consumer<? super T> action, Executor executor) Returns a new Cffu that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action.thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action.thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied action.thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action.thenAcceptBothFastFail(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action.thenAcceptBothFastFailAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied action.thenAcceptBothFastFailAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action.<U> Cffu<U> Returns a new Cffu that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function.<U> Cffu<U> thenApplyAsync(Function<? super T, ? extends U> fn) Returns a new Cffu that, when this stage completes normally, is executed usingdefaultExecutor(), with this stage's result as the argument to the supplied function.<U> Cffu<U> thenApplyAsync(Function<? super T, ? extends U> fn, Executor executor) Returns a new Cffu that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied function.<U,V> Cffu <V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function.<U,V> Cffu <V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied function.<U,V> Cffu <V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function.<U,V> Cffu <V> thenCombineFastFail(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function.<U,V> Cffu <V> thenCombineFastFailAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied function.<U,V> Cffu <V> thenCombineFastFailAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function.<U> Cffu<U> thenCompose(Function<? super T, ? extends CompletionStage<U>> fn) Returns a new Cffu that is completed with the same value as the CompletionStage returned by the given function.<U> Cffu<U> thenComposeAsync(Function<? super T, ? extends CompletionStage<U>> fn) Returns a new Cffu that is completed with the same value as the CompletionStage returned by the given function, executed usingdefaultExecutor().<U> Cffu<U> thenComposeAsync(Function<? super T, ? extends CompletionStage<U>> fn, Executor executor) Returns a new Cffu that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor.Returns a new Cffu that, when this stage completes normally, executes the given action.thenRunAsync(Runnable action) Returns a new Cffu that, when this stage completes normally, executes the given action usingdefaultExecutor().thenRunAsync(Runnable action, Executor executor) Returns a new Cffu that, when this stage completes normally, executes the given action using the supplied Executor.Returns aCompletableFuturemaintaining the same completion properties as this stage.toString()Returns a string identifying this Cffu, as well as its completion state.whenComplete(BiConsumer<? super T, ? super Throwable> action) Returns a new Cffu with the same result or exception as this stage, that executes the given action when this stage completes.whenCompleteAsync(BiConsumer<? super T, ? super Throwable> action) Returns a new Cffu with the same result or exception as this stage, that executes the given action usingdefaultExecutor()when this stage completes.whenCompleteAsync(BiConsumer<? super T, ? super Throwable> action, Executor executor) Returns a new Cffu with the same result or exception as this stage, that executes the given action using the supplied Executor when this stage completes.
-
Method Details
-
thenRun
Returns a new Cffu that, when this stage completes normally, executes the given action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenRunin interfaceCompletionStage<T>- Parameters:
action- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
- See Also:
-
thenRunAsync
Returns a new Cffu that, when this stage completes normally, executes the given action usingdefaultExecutor().See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenRunAsyncin interfaceCompletionStage<T>- Parameters:
action- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
- See Also:
-
thenRunAsync
Returns a new Cffu that, when this stage completes normally, executes the given action using the supplied Executor.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenRunAsyncin interfaceCompletionStage<T>- Parameters:
action- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
- See Also:
-
thenAccept
Returns a new Cffu that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenAcceptin interfaceCompletionStage<T>- Parameters:
action- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
- See Also:
-
thenAcceptAsync
Returns a new Cffu that, when this stage completes normally, is executed usingdefaultExecutor(), with this stage's result as the argument to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenAcceptAsyncin interfaceCompletionStage<T>- Parameters:
action- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
- See Also:
-
thenAcceptAsync
Returns a new Cffu that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenAcceptAsyncin interfaceCompletionStage<T>- Parameters:
action- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
- See Also:
-
thenApply
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenRun`") public <U> Cffu<U> thenApply(Function<? super T, ? extends U> fn) Returns a new Cffu that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function.This method is analogous to
Optional.mapandStream.map.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenApplyin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
fn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
- See Also:
-
thenApplyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenRunAsync`") public <U> Cffu<U> thenApplyAsync(Function<? super T, ? extends U> fn) Returns a new Cffu that, when this stage completes normally, is executed usingdefaultExecutor(), with this stage's result as the argument to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenApplyAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
fn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
- See Also:
-
thenApplyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenRunAsync`") public <U> Cffu<U> thenApplyAsync(Function<? super T, ? extends U> fn, Executor executor) Returns a new Cffu that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenApplyAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
fn- the function to use to compute the value of the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
- See Also:
-
runAfterBoth
Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
runAfterBothin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterBothAsync
Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action usingdefaultExecutor().See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
runAfterBothAsyncin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterBothAsync
Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action using the supplied executor.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
runAfterBothAsyncin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
runAfterBothFastFail
Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
runAfterBoth(CompletionStage, Runnable)except for the fast-fail behavior.- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterBothFastFailAsync
Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action usingdefaultExecutor(). if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
runAfterBothAsync(CompletionStage, Runnable)except for the fast-fail behavior.- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterBothFastFailAsync
public Cffu<Void> runAfterBothFastFailAsync(CompletionStage<?> other, Runnable action, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, executes the given action using the supplied executor. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
runAfterBothAsync(CompletionStage, Runnable, Executor)except for the fast-fail behavior.- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
thenAcceptBoth
public <U> Cffu<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenAcceptBothin interfaceCompletionStage<T>- Type Parameters:
U- the type of the other CompletionStage's result- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
thenAcceptBothAsync
public <U> Cffu<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the type of the other CompletionStage's result- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
thenAcceptBothAsync
public <U> Cffu<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the type of the other CompletionStage's result- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
thenAcceptBothFastFail
public <U> Cffu<Void> thenAcceptBothFastFail(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
thenAcceptBoth(CompletionStage, BiConsumer)except for the fast-fail behavior.- Type Parameters:
U- the type of the other CompletionStage's result- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
thenAcceptBothFastFailAsync
public <U> Cffu<Void> thenAcceptBothFastFailAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied action. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
thenAcceptBothAsync(CompletionStage, BiConsumer)except for the fast-fail behavior.- Type Parameters:
U- the type of the other CompletionStage's result- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
thenAcceptBothFastFailAsync
public <U> Cffu<Void> thenAcceptBothFastFailAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
thenAcceptBothAsync(CompletionStage, BiConsumer, Executor)except for the fast-fail behavior.- Type Parameters:
U- the type of the other CompletionStage's result- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
thenCombine
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenAcceptBoth`") public <U,V> Cffu<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenCombinein interfaceCompletionStage<T>- Type Parameters:
U- the type of the other CompletionStage's resultV- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
thenCombineAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenAcceptBothAsync`") public <U,V> Cffu<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenCombineAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the type of the other CompletionStage's resultV- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
thenCombineAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenAcceptBothAsync`") public <U,V> Cffu<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenCombineAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the type of the other CompletionStage's resultV- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
thenCombineFastFail
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenAcceptBothFastFail`") public <U,V> Cffu<V> thenCombineFastFail(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
thenCombine(CompletionStage, BiFunction)except for the fast-fail behavior.- Type Parameters:
U- the type of the other CompletionStage's resultV- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
thenCombineFastFailAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenAcceptBothFastFailAsync`") public <U,V> Cffu<V> thenCombineFastFailAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) Returns a new Cffu that, when this and the other given stage both complete normally, is executed usingdefaultExecutor(), with the two results as arguments to the supplied function. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
thenCombineAsync(CompletionStage, BiFunction)except for the fast-fail behavior.- Type Parameters:
U- the type of the other CompletionStage's resultV- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
thenCombineFastFailAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `thenAcceptBothFastFailAsync`") public <U,V> Cffu<V> thenCombineFastFailAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) Returns a new Cffu that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function. if any of the given stage complete exceptionally, then the returned Cffu also does so *without* waiting other incomplete given CompletionStage, with a CompletionException holding this exception as its cause.This method is the same as
thenCombineAsync(CompletionStage, BiFunction, Executor)except for the fast-fail behavior.- Type Parameters:
U- the type of the other CompletionStage's resultV- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
allTupleOf
This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOf(cf2);is the same as:
allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2);- Returns:
- the new Cffu
- See Also:
-
allTupleOfFastFail
@Contract(pure=true) public <T2> Cffu<Tuple2<T,T2>> allTupleOfFastFail(CompletionStage<? extends T2> cf2) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOfFastFail(cf2);is the same as:
allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2);- Returns:
- the new Cffu
- See Also:
-
allTupleOf
@Contract(pure=true) public <T2,T3> Cffu<Tuple3<T,T2, allTupleOfT3>> (CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3) This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOf(cf2, cf3);is the same as:
allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2, cf3);- Returns:
- the new Cffu
- See Also:
-
allTupleOfFastFail
@Contract(pure=true) public <T2,T3> Cffu<Tuple3<T,T2, allTupleOfFastFailT3>> (CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOfFastFail(cf2, cf3);is the same as:
allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2, cf3);- Returns:
- the new Cffu
- See Also:
-
allTupleOf
@Contract(pure=true) public <T2,T3, Cffu<Tuple4<T,T4> T2, allTupleOfT3, T4>> (CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4) This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOf(cf2, cf3, cf4);is the same as:
allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2, cf3, cf4);- Returns:
- the new Cffu
- See Also:
-
allTupleOfFastFail
@Contract(pure=true) public <T2,T3, Cffu<Tuple4<T,T4> T2, allTupleOfFastFailT3, T4>> (CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOfFastFail(cf2, cf3, cf4);is the same as:
allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2, cf3, cf4);- Returns:
- the new Cffu
- See Also:
-
allTupleOf
@Contract(pure=true) public <T2,T3, Cffu<Tuple5<T,T4, T5> T2, allTupleOfT3, T4, T5>> (CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4, CompletionStage<? extends T5> cf5) This method is the same asCffuFactory.allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOf(cf2, cf3, cf4, cf5);is the same as:
allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2, cf3, cf4, cf5);- Returns:
- the new Cffu
- See Also:
-
allTupleOfFastFail
@Contract(pure=true) public <T2,T3, Cffu<Tuple5<T,T4, T5> T2, allTupleOfFastFailT3, T4, T5>> (CompletionStage<? extends T2> cf2, CompletionStage<? extends T3> cf3, CompletionStage<? extends T4> cf4, CompletionStage<? extends T5> cf5) This method is the same asCffuFactory.allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage), providing this method is convenient for method chaining.Calling this method
allTuple = cffu.allTupleOfFastFail(cf2, cf3, cf4, cf5);is the same as:
allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2, cf3, cf4, cf5);- Returns:
- the new Cffu
- See Also:
-
runAfterEither
Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
runAfterEitherin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterEitherAsync
Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action usingdefaultExecutor().See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterEitherAsync
Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action using the supplied executor.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
runAfterEitherSuccess
Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action. Otherwise, all two complete exceptionally, the returned CompletableFuture also does so, with a CompletionException holding an exception from any of as its cause.This method is the same as
runAfterEither(CompletionStage, Runnable)except for the either-success behavior(not either-complete).- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterEitherSuccessAsync
Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action usingdefaultExecutor().See the
CompletionStagedocumentation for rules covering exceptional completion.- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
runAfterEitherSuccessAsync
public Cffu<Void> runAfterEitherSuccessAsync(CompletionStage<?> other, Runnable action, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, executes the given action using the supplied executor.See the
CompletionStagedocumentation for rules covering exceptional completion.- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
acceptEither
Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
acceptEitherin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
acceptEitherAsync
Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
acceptEitherAsyncin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
acceptEitherAsync
public Cffu<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
acceptEitherAsyncin interfaceCompletionStage<T>- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
acceptEitherSuccess
public Cffu<Void> acceptEitherSuccess(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action.This method is the same as
acceptEither(CompletionStage, Consumer)except for the either-success behavior(not either-complete).- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
acceptEitherSuccessAsync
public Cffu<Void> acceptEitherSuccessAsync(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied action.This method is the same as
acceptEitherAsync(CompletionStage, Consumer)except for the either-success behavior(not either-complete).- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffu- Returns:
- the new Cffu
-
acceptEitherSuccessAsync
public Cffu<Void> acceptEitherSuccessAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action.This method is the same as
acceptEitherAsync(CompletionStage, Consumer, Executor)except for the either-success behavior(not either-complete).- Parameters:
other- the other CompletionStageaction- the action to perform before completing the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
applyToEither
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `acceptEither`") public <U> Cffu<U> applyToEither(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
applyToEitherin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
applyToEitherAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `acceptEitherAsync`") public <U> Cffu<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
applyToEitherAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
applyToEitherAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `acceptEitherAsync`") public <U> Cffu<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
applyToEitherAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
applyToEitherSuccess
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `acceptEitherSuccess`") public <U> Cffu<U> applyToEitherSuccess(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function.This method is the same as
applyToEither(CompletionStage, Function)except for the either-success behavior(not either-complete).- Type Parameters:
U- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
applyToEitherSuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `acceptEitherSuccessAsync`") public <U> Cffu<U> applyToEitherSuccessAsync(CompletionStage<? extends T> other, Function<? super T, U> fn) Returns a new Cffu that, when either this or the other given stage complete normally, is executed usingdefaultExecutor(), with the corresponding result as argument to the supplied function.This method is the same as
applyToEitherAsync(CompletionStage, Function)except for the either-success behavior(not either-complete).- Type Parameters:
U- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
applyToEitherSuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `acceptEitherSuccessAsync`") public <U> Cffu<U> applyToEitherSuccessAsync(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) Returns a new Cffu that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function.This method is the same as
applyToEitherAsync(CompletionStage, Function, Executor)except for the either-success behavior(not either-complete).- Type Parameters:
U- the function's return type- Parameters:
other- the other CompletionStagefn- the function to use to compute the value of the returned Cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
exceptionally
Returns a new Cffu that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function. Otherwise, if this stage completes normally, then the returned stage also completes normally with the same value.- Specified by:
exceptionallyin interfaceCompletionStage<T>- Parameters:
fn- the function to use to compute the value of the returned Cffu if this Cffu completed exceptionally- Returns:
- the new Cffu
-
exceptionallyAsync
Returns a new Cffu that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, usingdefaultExecutor(). Otherwise, if this stage completes normally, then the returned stage also completes normally with the same value.- Specified by:
exceptionallyAsyncin interfaceCompletionStage<T>- Parameters:
fn- the function to use to compute the value of the returned Cffu if this Cffu completed exceptionally- Returns:
- the new Cffu
-
exceptionallyAsync
Returns a new Cffu that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, using the supplied Executor. Otherwise, if this stage completes normally, then the returned stage also completes normally with the same value.- Specified by:
exceptionallyAsyncin interfaceCompletionStage<T>- Parameters:
fn- the function to use to compute the value of the returned Cffu if this Cffu completed exceptionallyexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
orTimeout
Exceptionally completes this Cffu with aTimeoutExceptionif not otherwise completed before the given timeout.- Parameters:
timeout- how long to wait before completing exceptionally with a TimeoutException, in units ofunitunit- aTimeUnitdetermining how to interpret thetimeoutparameter- Returns:
- this Cffu
- See Also:
-
completeOnTimeout
Completes this Cffu with the given value if not otherwise completed before the given timeout.- Parameters:
value- the value to use upon timeouttimeout- how long to wait before completing normally with the given value, in units ofunitunit- aTimeUnitdetermining how to interpret thetimeoutparameter- Returns:
- this Cffu
- See Also:
-
thenCompose
Returns a new Cffu that is completed with the same value as the CompletionStage returned by the given function.When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the Cffu returned by this method is completed with the same value.
To ensure progress, the supplied function must arrange eventual completion of its result.
This method is analogous to
Optional.flatMapandStream.flatMap.See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenComposein interfaceCompletionStage<T>- Type Parameters:
U- the type of the returned Cffu's result- Parameters:
fn- the function to use to compute another CompletionStage- Returns:
- the new Cffu
-
thenComposeAsync
Returns a new Cffu that is completed with the same value as the CompletionStage returned by the given function, executed usingdefaultExecutor().When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the Cffu returned by this method is completed with the same value.
To ensure progress, the supplied function must arrange eventual completion of its result.
See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenComposeAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the type of the returned Cffu's result- Parameters:
fn- the function to use to compute another CompletionStage- Returns:
- the new Cffu
-
thenComposeAsync
public <U> Cffu<U> thenComposeAsync(Function<? super T, ? extends CompletionStage<U>> fn, Executor executor) Returns a new Cffu that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor.When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the Cffu returned by this method is completed with the same value.
To ensure progress, the supplied function must arrange eventual completion of its result.
See the
CompletionStagedocumentation for rules covering exceptional completion.- Specified by:
thenComposeAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the type of the returned Cffu's result- Parameters:
fn- the function to use to compute another CompletionStageexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
exceptionallyCompose
Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception.- Specified by:
exceptionallyComposein interfaceCompletionStage<T>- Parameters:
fn- the function to use to compute the returned CompletionStage if this CompletionStage completed exceptionally- Returns:
- the new CompletionStage
-
exceptionallyComposeAsync
Returns a new Cffu that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, usingdefaultExecutor().- Specified by:
exceptionallyComposeAsyncin interfaceCompletionStage<T>- Parameters:
fn- the function to use to compute the returned CompletionStage if this Cffu completed exceptionally- Returns:
- the new Cffu
-
exceptionallyComposeAsync
public Cffu<T> exceptionallyComposeAsync(Function<Throwable, ? extends CompletionStage<T>> fn, Executor executor) Returns a new Cffu that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, using the supplied Executor.- Specified by:
exceptionallyComposeAsyncin interfaceCompletionStage<T>- Parameters:
fn- the function to use to compute the returned CompletionStage if this Cffu completed exceptionallyexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
handle
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `whenComplete`") public <U> Cffu<U> handle(BiFunction<? super T, Throwable, ? extends U> fn) Returns a new Cffu that, when this cffu completes either normally or exceptionally, is executed with this cffu's result and exception as arguments to the supplied function.When this cffu is complete, the given function is invoked with the result (or
nullif none) and the exception (ornullif none) of this cffu as arguments, and the function's result is used to complete the returned cffu.- Specified by:
handlein interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
fn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
handleAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `whenCompleteAsync`") public <U> Cffu<U> handleAsync(BiFunction<? super T, Throwable, ? extends U> fn) Returns a new Cffu that, when this cffu completes either normally or exceptionally, is executed usingdefaultExecutor(), with this cffu's result and exception as arguments to the supplied function.When this Cffu is complete, the given function is invoked with the result (or
nullif none) and the exception (ornullif none) of this Cffu as arguments, and the function's result is used to complete the returned Cffu.- Specified by:
handleAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
fn- the function to use to compute the value of the returned Cffu- Returns:
- the new Cffu
-
handleAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `whenCompleteAsync`") public <U> Cffu<U> handleAsync(BiFunction<? super T, Throwable, ? extends U> fn, Executor executor) Returns a new Cffu that, when this cffu completes either normally or exceptionally, is executed using the supplied executor, with this cffu's result and exception as arguments to the supplied function.When this cffu is complete, the given function is invoked with the result (or
nullif none) and the exception (ornullif none) of this cffu as arguments, and the function's result is used to complete the returned cffu.- Specified by:
handleAsyncin interfaceCompletionStage<T>- Type Parameters:
U- the function's return type- Parameters:
fn- the function to use to compute the value of the returned cffuexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
whenComplete
Returns a new Cffu with the same result or exception as this stage, that executes the given action when this stage completes.When this stage is complete, the given action is invoked with the result (or
nullif none) and the exception (ornullif none) of this stage as arguments. The returned stage is completed when the action returns.Unlike method
handle, this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: if this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception.- Specified by:
whenCompletein interfaceCompletionStage<T>- Parameters:
action- the action to perform- Returns:
- the new Cffu
-
whenCompleteAsync
Returns a new Cffu with the same result or exception as this stage, that executes the given action usingdefaultExecutor()when this stage completes.When this stage is complete, the given action is invoked with the result (or
nullif none) and the exception (ornullif none) of this stage as arguments. The returned stage is completed when the action returns.Unlike method
handleAsync, this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: If this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception.- Specified by:
whenCompleteAsyncin interfaceCompletionStage<T>- Parameters:
action- the action to perform- Returns:
- the new Cffu
-
whenCompleteAsync
Returns a new Cffu with the same result or exception as this stage, that executes the given action using the supplied Executor when this stage completes.When this stage is complete, the given action is invoked with the result (or
nullif none) and the exception (ornullif none) of this stage as arguments. The returned stage is completed when the action returns.Unlike method
handleAsync, this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: If this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception.- Specified by:
whenCompleteAsyncin interfaceCompletionStage<T>- Parameters:
action- the action to performexecutor- the executor to use for asynchronous execution- Returns:
- the new Cffu
-
peek
Peeks the result by executing the given action when this cffu completes, returns this cffu.When this cffu is complete, the given action is invoked with the result (or
nullif none) and the exception (ornullif none) of this cffu as arguments. Whether the supplied action throws an exception or not, do NOT affect this cffu.Unlike method
handleand like methodwhenComplete, this method is not designed to translate completion outcomes.- Parameters:
action- the action to perform- Returns:
- this Cffu
- See Also:
-
peekAsync
Peeks the result by executing the given action when this cffu completes, executes the given action usingdefaultExecutor(), returns this cffu.When this cffu is complete, the given action is invoked with the result (or
nullif none) and the exception (ornullif none) of this cffu as arguments. Whether the supplied action throws an exception or not, do NOT affect this cffu.Unlike method
handleand like methodwhenComplete, this method is not designed to translate completion outcomes.- Parameters:
action- the action to perform- Returns:
- this Cffu
- See Also:
-
peekAsync
Peeks the result by executing the given action when this cffu completes, that executes the given action using the supplied Executor when this cffu completes, returns this cffu.When this cffu is complete, the given action is invoked with the result (or
nullif none) and the exception (ornullif none) of this cffu as arguments. Whether the supplied action throws an exception or not, do NOT affect this cffu.Unlike method
handleand like methodwhenComplete, this method is not designed to translate completion outcomes.- Parameters:
action- the action to perform- Returns:
- this Cffu
- See Also:
-
get
Waits if necessary for the computation to complete, and then retrieves its result.- Specified by:
getin interfaceFuture<T>- Returns:
- the computed result
- Throws:
CancellationException- if the computation was cancelledExecutionException- if the computation threw an exceptionInterruptedException- if the current thread was interrupted while waiting- See Also:
-
get
@Blocking @Nullable public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.- Specified by:
getin interfaceFuture<T>- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the computed result
- Throws:
CancellationException- if the computation was cancelledExecutionException- if the computation threw an exceptionInterruptedException- if the current thread was interrupted while waitingTimeoutException- if the wait timed out- See Also:
-
join
Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally.To better conform with the use of common functional forms, if a computation involved in the completion of this Cffu threw an exception, this method throws an (unchecked)
CompletionExceptionwith the underlying exception as its cause.- Returns:
- the result value
- Throws:
CancellationException- if the computation was cancelledCompletionException- if this future completed exceptionally or a completion computation threw an exception- See Also:
-
join
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result value when complete, or throws an (unchecked) exception if completed exceptionally.NOTE:
Calling this methodresult = cffu.join(timeout, unit);is the same as:
CAUTION:result = cffu.copy() // defensive copy to avoid writing this cffu unexpectedly .orTimeout(timeout, unit) .join();
if the wait timed out, this method throws an (unchecked)CompletionExceptionwith theTimeoutExceptionas its cause; NOT throws a (checked)TimeoutExceptionlikeget(long, TimeUnit).- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the result value
- Throws:
CancellationException- if the computation was cancelledCompletionException- if this future completed exceptionally or a completion computation threw an exception or the wait timed out(with theTimeoutExceptionas its cause)- See Also:
-
getNow
Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.- Parameters:
valueIfAbsent- the value to return if not completed- Returns:
- the result value, if completed, else the given valueIfAbsent
- Throws:
CancellationException- if the computation was cancelledCompletionException- if this future completed exceptionally or a completion computation threw an exception- See Also:
-
resultNow
Returns the computed result, without waiting.This method is for cases where the caller knows that the task has already completed successfully, for example when filtering a stream of Future objects for the successful tasks and using a mapping operation to obtain a stream of results.
results = futures.stream() .filter(f -> f.state() == Future.State.SUCCESS) .map(Future::resultNow) .toList(); -
exceptionNow
Returns the exception thrown by the task, without waiting.This method is for cases where the caller knows that the task has already completed with an exception.
- Specified by:
exceptionNowin interfaceFuture<T>- Returns:
- the exception thrown by the task
- Throws:
IllegalStateException- if the task has not completed, the task completed normally, or the task was cancelled- See Also:
-
isDone
Returnstrueif this task completed.Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return
true. -
isCompletedExceptionally
Returnstrueif this Cffu completed exceptionally, in any way. Possible causes include cancellation, explicit invocation ofcompleteExceptionally, and abrupt termination of a CompletionStage action.- Returns:
trueif this Cffu completed exceptionally
-
isCancelled
Returnstrueif this Cffu was cancelled before it completed normally.- Specified by:
isCancelledin interfaceFuture<T>- Returns:
trueif this Cffu was cancelled before it completed normally
-
state
Returns the computation state, this method contains NO java version compatibility logic, if you need this function in oldjava 18-, usecffuState()instead.NOTE:
CompletableFuture.state()is new method since Java 19, this method should have compatibility logic for old Java version; But the return typeFuture.Stateis also added since Java 19, so it's IMPOSSIBLE to backport by compatibility logic of wrapper class(Cffu). -
cffuState
Returns the computation state(CffuState), this method is equivalent toCompletableFuture.state()with java version compatibility logic, so you can invoke in oldjava 18-.- Returns:
- the computation state
- See Also:
-
complete
If not already completed, sets the value returned byget()and related methods to the given value.- Parameters:
value- the result value- Returns:
trueif this invocation caused this Cffu to transition to a completed state, elsefalse
-
completeAsync
Completes this Cffu with the result of the given Supplier function invoked from an asynchronous task usingdefaultExecutor().- Parameters:
supplier- a function returning the value to be used to complete this Cffu- Returns:
- this Cffu
-
completeAsync
Completes this Cffu with the result of the given Supplier function invoked from an asynchronous task using the given executor.- Parameters:
supplier- a function returning the value to be used to complete this Cffuexecutor- the executor to use for asynchronous execution- Returns:
- this Cffu
-
completeExceptionally
If not already completed, causes invocations ofget()and related methods to throw the given exception.- Parameters:
ex- the exception- Returns:
trueif this invocation caused this Cffu to transition to a completed state, elsefalse
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) If not already completed, completes this Cffu with aCancellationException. Dependent Cffus that have not already completed will also complete exceptionally, with aCompletionExceptioncaused by thisCancellationException. -
minimalCompletionStage
Returns a new CompletionStage that is completed normally with the same value as this CompletableFuture when it completes normally, and cannot be independently completed or otherwise used in ways not defined by the methods of interfaceCompletionStage. If this CompletableFuture completes exceptionally, then the returned CompletionStage completes exceptionally with a CompletionException with this exception as cause.CAUTION:
if run on old Java 8, just return a Cffu with a *normal* underlying CompletableFuture which is NOT with a *minimal* CompletionStage.demo code about re-config methods of Cffu:
cffu2 = cffu .resetCffuFactory(cffuFactory2) // reset to use config from cffuFactory2 .minimalCompletionStage(); // restrict to methods of CompletionStage- See Also:
-
resetCffuFactory
Returns a new Cffu with given CffuFactory(contained configuration) that is completed normally with the same value as this Cffu when it completes normally. If this Cffu completes exceptionally, then the returned Cffu completes exceptionally with a CompletionException with this exception as cause.demo code about re-config methods of Cffu:
cffu2 = cffu .resetCffuFactory(cffuFactory2) // reset to use config from cffuFactory2 .minimalCompletionStage(); // restrict to methods of CompletionStage- Parameters:
cffuFactory- cffuFactory contained configuration- Returns:
- the new Cffu
- See Also:
-
toCompletableFuture
Returns aCompletableFuturemaintaining the same completion properties as this stage.call
CompletableFuture.toCompletableFuture()method of the underlying CompletableFuture:underlyingCf.toCompletableFuture(); if you need the underlying CompletableFuture instance, call methodcffuUnwrap().CompletableFutureUtils.toCompletableFutureArray(CompletionStage[])is the batch operation to this method.- Specified by:
toCompletableFuturein interfaceCompletionStage<T>- Returns:
- the CompletableFuture
- See Also:
-
copy
Returns a new Cffu that is completed normally with the same value as this Cffu when it completes normally. If this Cffu completes exceptionally, then the returned Cffu completes exceptionally with a CompletionException with this exception as cause. The behavior is equivalent tothenApply(x -> x). This method may be useful as a form of "defensive copying", to prevent clients from completing, while still being able to arrange dependent actions.- Returns:
- the new Cffu
-
defaultExecutor
Returns the default Executor used for async methods that do not specify an Executor. Config from theCffuFactory.defaultExecutor(), and can re-configured byresetCffuFactory(CffuFactory).- Returns:
- the default executor
- See Also:
-
cffuFactory
Returns theCffuFactoryof this Cffu. This can be re-configured byresetCffuFactory(CffuFactory).- Returns:
- the CffuFactory
- See Also:
-
forbidObtrudeMethods
ReturnsforbidObtrudeMethodsor not. This can be re-configured byresetCffuFactory(CffuFactory).- See Also:
-
isMinimalStage
Returns whether is aminimal stageor not.create a
minimal stageby below methods:CffuFactory.completedStage(Object)CffuFactory.failedStage(Throwable)minimalCompletionStage()CffuFactory.toCffu(CompletionStage), this method return aminimal stagewhen input aminimal stage, otherwise return a normal stage.
-
cffuUnwrap
Returns the underlying CompletableFuture.CffuFactory.toCffu(CompletionStage)is inverse operation to this method.CffuFactory.cffuArrayUnwrap(Cffu[])is the batch operation to this method.- Returns:
- the underlying CompletableFuture
- See Also:
-
getNumberOfDependents
Returns the estimated number of Cffus whose completions are awaiting completion of this Cffu. This method is designed for use in monitoring system state, not for synchronization control.- Returns:
- the number of dependent Cffus
- See Also:
-
obtrudeValue
Forcibly sets or resets the value subsequently returned by methodget()and related methods, whether or not already completed. This method is designed for use only in error recovery actions, and even in such situations may result in ongoing dependent completions using established versus overwritten outcomes.- Parameters:
value- the completion value- See Also:
-
obtrudeException
Forcibly causes subsequent invocations of methodget()and related methods to throw the given exception, whether or not already completed. This method is designed for use only in error recovery actions, and even in such situations may result in ongoing dependent completions using established versus overwritten outcomes.- Parameters:
ex- the exception- Throws:
NullPointerException- if the exception is null- See Also:
-
newIncompleteFuture
Returns a new incomplete Cffu with CompletableFuture of the type to be returned by a CompletionStage method. Subclasses of CompletableFuture should normally override this method to return an instance of the same class as this CompletableFuture. The default implementation returns an instance of class CompletableFuture.NOTE:
this method existed mainly for API compatibility toCompletableFuture, preferCffuFactory.newIncompleteCffu().CAUTION:
for minimal stage instance(isMinimalStage()), if run on old Java 8, just return a Cffu with a *normal* underlying CompletableFuture which is NOT with a *minimal* CompletionStage.- See Also:
-
toString
Returns a string identifying this Cffu, as well as its completion state.The state, in brackets, contains the String
"Completed Normally"or the String"Completed Exceptionally", or the String"Not completed"followed by the number of Cffus dependent upon its completion, if any.
-