@FunctionalInterface public interface TargetState
yet.
The reference to a TargetState should
be named as the state it models
when the state has been reached.
E.g:
TargetState isShutdown = ...
...
if(isShutdown.yet()) {
...
}
Or to run a repeating task until the target state is reached using untilThen(Runnable, Consumer):
TargetState isShutdown = ...
...
isShutdown.untilThen(() -> {
...
}, exception -> handle(exception));
| Modifier and Type | Interface and Description |
|---|---|
static class |
TargetState.TaskControl
Control signals returned from tasks to control
execution with
untilThen(Supplier, Consumer) |
| Modifier and Type | Field and Description |
|---|---|
static TargetState |
IMMEDIATELY
A target state which is already reached.
|
static TargetState |
NEVER
A target state which will never be reached.
|
| Modifier and Type | Method and Description |
|---|---|
static TargetState |
all(Iterable<? extends TargetState> states) |
static TargetState |
all(TargetState... states) |
default TargetState |
or(TargetState that) |
default void |
untilThen(Runnable loopingTask,
Consumer<? super Exception> exceptionHandler)
Run a task in a loop until the target state is reached (
yet() returns true). |
default void |
untilThen(Supplier<TargetState.TaskControl> loopingTask,
Consumer<? super Exception> exceptionHandler)
Run a task in a loop until the target state is reached (
yet() returns true),
though the loop can be controlled to exit prematurely using TargetState.TaskControl.EXIT. |
boolean |
yet()
Tell if the target state has been reached yet.
|
static final TargetState IMMEDIATELY
static final TargetState NEVER
boolean yet()
true, it will never return false again.true when the target state has been reached,
false otherwise.default void untilThen(Supplier<TargetState.TaskControl> loopingTask, Consumer<? super Exception> exceptionHandler)
yet() returns true),
though the loop can be controlled to exit prematurely using TargetState.TaskControl.EXIT.
Any exceptions thrown by the task is caught and forwarded to the given handler, and
then the loop is continued. If the exceptionHandler itself throws an exception,
the loop is exited, and the exception is propagated to the caller of
until(..).loopingTask - the task to run repeatedly.exceptionHandler - the exception handler.default void untilThen(Runnable loopingTask, Consumer<? super Exception> exceptionHandler)
yet() returns true).
Any exceptions thrown by the task is caught and forwarded to the given handler, and
then the loop is continued. If the exceptionHandler itself throws an exception,
the loop is exited, and the exception is propagated to the caller of
until(..).loopingTask - the task to run repeatedly.exceptionHandler - the exception handler.default TargetState or(TargetState that)
static TargetState all(TargetState... states)
static TargetState all(Iterable<? extends TargetState> states)
Copyright © 2019 Digipost. All rights reserved.