T
- The type of result of the CompletableFuture
public interface WaitResultBuilder6<T>
CompletableFuture
to create the
completable operation it self.Modifier and Type | Method | Description |
---|---|---|
CompletableFuture<Optional<T>> |
asyncExec() |
Create and start the async execution of the
CompletableFuture the
executor that was defined before. |
default Optional<T> |
finish() |
Directly wait for the result of this execution.
|
default T |
finishWithAResult() |
Directly wait for a positive result of this execution.
|
default Optional<T> |
get() |
Waits if necessary for the produced future to complete, and then returns its
result.
|
default Optional<T> |
join() |
Shortcut method to the join of the
CompletableFuture . |
default T |
joinWithAResult() |
Shortcut method to the join of the
CompletableFuture , that expect a
positive result. |
default CompletionStage<Optional<T>> |
minimalCompletionStage() |
Returns a new CompletionStage that is completed normally based on this
CompletableFuture . |
default CompletableFuture<Optional<T>> |
orTimeout(long timeout,
TimeUnit unit) |
Create and start the async execution of the
CompletableFuture and
exceptionally completes this CompletableFuture with a TimeoutException if not
otherwise completed before the given timeout. |
default CompletableFuture<Void> |
thenAccept(Consumer<? super Optional<T>> action) |
Create and start the async execution of the
CompletableFuture and
directly register a Consumer on the result. |
default <U> CompletableFuture<U> |
thenApply(Function<? super Optional<T>,? extends U> fn) |
Create and start the async execution of the
CompletableFuture and
directly register a Function on the result. |
CompletableFuture<Optional<T>> asyncExec()
CompletableFuture
the
executor that was defined before.
This method is the main method of this interface. This start the
execution of the CompletableFuture
based on the parameter defined
before.
For example:
CompletableFuture<Optional<String>> future = WaitResult.of(myCallable).dontIgnoreException() .expecting(myPredicate).repeat(2).every(1000, TimeUnit.MILLISECONDS).usingDefaultExecutor().asyncExec();This defines a
CompletableFuture
that will repeat maximum two time,
with a wait time of 1000ms, the execution of myCallable
, doesn't
ignore the exception, verify the myPredicate
condition. This
CompletableFuture
will use the default executor.CompletableFuture
default Optional<T> finish()
AssertionError
is thrown.
This method is a shortcut method to asyncExec().get()
, which
throw AssertionError in case of error.
Optional
with the result of the executionAssertionError
- In case of not ignored exception.asyncExec()
,
CompletableFuture.get()
default T finishWithAResult()
AssertionError
is
thrown.
This method is a shortcut method to the finish method that read the optional value and throw an AssertionError in case of mission value.
AssertionError
- In case of not ignored exception or missing result.finish()
default Optional<T> join()
CompletableFuture
.
Only runtime exception in case of error.
CompletableFuture.join()
,
asyncExec()
default T joinWithAResult()
CompletableFuture
, that expect a
positive result.
Only runtime exception in case of error.
CompletableFuture.join()
,
join()
default CompletableFuture<Void> thenAccept(Consumer<? super Optional<T>> action)
CompletableFuture
and
directly register a Consumer on the result.action
- the action to be done on the resultCompletableFuture
CompletableFuture.thenAccept(Consumer)
,
asyncExec()
default <U> CompletableFuture<U> thenApply(Function<? super Optional<T>,? extends U> fn)
CompletableFuture
and
directly register a Function on the result.U
- The new return typefn
- then function to be appliedCompletableFuture
CompletableFuture.thenApply(Function)
,
asyncExec()
default CompletableFuture<Optional<T>> orTimeout(long timeout, TimeUnit unit)
CompletableFuture
and
exceptionally completes this CompletableFuture with a TimeoutException if not
otherwise completed before the given timeout.
Only available on java 9
timeout
- how long to wait before completing exceptionally with a
TimeoutException, in units of unitunit
- a TimeUnit determining how to interpret the timeout parameterCompletableFuture
CompletableFuture.orTimeout(long, TimeUnit)
,
asyncExec()
default CompletionStage<Optional<T>> minimalCompletionStage()
CompletableFuture
.
Only available on java 9
CompletableFuture.minimalCompletionStage()
,
asyncExec()
default Optional<T> get() throws InterruptedException, ExecutionException
CancellationException
- if the produced future was cancelledExecutionException
- if the produced future completed exceptionallyInterruptedException
- if the current thread was interrupted while waitingCompletableFuture.get()
,
asyncExec()
Copyright © 2021. All rights reserved.