Package io.micronaut.core.execution
Interface ExecutionFlow<T>
- Type Parameters:
T- The flow type
- All Known Subinterfaces:
CompletableFutureExecutionFlow<T>,DelayedExecutionFlow<T>,ImperativeExecutionFlow<T>,ReactiveExecutionFlow<T>
The execution flow class represents a data flow which state can be represented as a simple imperative flow or an async/reactive.
The state can be resolved or lazy - based on the implementation.
NOTE: The instance of the flow is not supposed to be used after a mapping operator is used.
- Since:
- 4.0.0
- Author:
- Denis Stepanov
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NonNull ExecutionFlow<T>Create a flow by invoking a supplier asynchronously.static <T> @NonNull ExecutionFlow<T>empty()Create a simple flow representing an empty state.static <K> @NonNull ExecutionFlow<K>Create a simple flow representing an error.<R> @NonNull ExecutionFlow<R>flatMap(@NonNull Function<? super T, ? extends ExecutionFlow<? extends R>> transformer) Map a not-empty value to a new flow.static <K> @NonNull ExecutionFlow<K>just(K value) Create a simple flow representing a value.<R> @NonNull ExecutionFlow<R>Map a not-empty value.voidonComplete(@NonNull BiConsumer<? super T, Throwable> fn) Invokes a provided function when the flow is resolved, or immediately if it is already done.onErrorResume(@NonNull Function<? super Throwable, ? extends ExecutionFlow<? extends T>> fallback) Supply a new flow if the existing flow is erroneous.putInContext(@NonNull String key, @NonNull Object value) Store a contextual value.<R> @NonNull ExecutionFlow<R>then(@NonNull Supplier<? extends ExecutionFlow<? extends R>> supplier) Supply a new flow after the existing flow value is resolved.default @NonNull CompletableFuture<T>Converts the existing flow into the completable future.Create anImperativeExecutionFlowfrom this execution flow, if possible.Alternative totryComplete()which will unwrap the flow's error.default TAlternative totryComplete()which will unwrap the flow's value.
-
Method Details
-
just
Create a simple flow representing a value.- Type Parameters:
K- The value type- Parameters:
value- The value- Returns:
- a new flow
-
error
Create a simple flow representing an error.- Type Parameters:
K- The value type- Parameters:
e- The exception- Returns:
- a new flow
-
empty
Create a simple flow representing an empty state.- Type Parameters:
T- The flow value type- Returns:
- a new flow
-
async
@NonNull static <T> @NonNull ExecutionFlow<T> async(@NonNull @NonNull Executor executor, @NonNull @NonNull Supplier<? extends ExecutionFlow<T>> supplier) Create a flow by invoking a supplier asynchronously.- Type Parameters:
T- The flow value type- Parameters:
executor- The executorsupplier- The supplier- Returns:
- a new flow
-
map
@NonNull <R> @NonNull ExecutionFlow<R> map(@NonNull @NonNull Function<? super T, ? extends R> transformer) Map a not-empty value.- Type Parameters:
R- New value Type- Parameters:
transformer- The value transformer- Returns:
- a new flow
-
flatMap
@NonNull <R> @NonNull ExecutionFlow<R> flatMap(@NonNull @NonNull Function<? super T, ? extends ExecutionFlow<? extends R>> transformer) Map a not-empty value to a new flow.- Type Parameters:
R- New value Type- Parameters:
transformer- The value transformer- Returns:
- a new flow
-
then
@NonNull <R> @NonNull ExecutionFlow<R> then(@NonNull @NonNull Supplier<? extends ExecutionFlow<? extends R>> supplier) Supply a new flow after the existing flow value is resolved.- Type Parameters:
R- New value Type- Parameters:
supplier- The supplier- Returns:
- a new flow
-
onErrorResume
@NonNull @NonNull ExecutionFlow<T> onErrorResume(@NonNull @NonNull Function<? super Throwable, ? extends ExecutionFlow<? extends T>> fallback) Supply a new flow if the existing flow is erroneous.- Parameters:
fallback- The fallback- Returns:
- a new flow
-
putInContext
@NonNull @NonNull ExecutionFlow<T> putInContext(@NonNull @NonNull String key, @NonNull @NonNull Object value) Store a contextual value.- Parameters:
key- The keyvalue- The value- Returns:
- a new flow
-
onComplete
Invokes a provided function when the flow is resolved, or immediately if it is already done.- Parameters:
fn- The function
-
tryComplete
Create anImperativeExecutionFlowfrom this execution flow, if possible. The flow will have its result immediately available.- Returns:
- The imperative flow, or
nullif this flow is not complete or does not support this operation
-
tryCompleteValue
Alternative totryComplete()which will unwrap the flow's value.- Returns:
- The imperative flow then returns its value, or
nullif this flow is not complete or does not support this operation - Since:
- 4.3
-
tryCompleteError
Alternative totryComplete()which will unwrap the flow's error.- Returns:
- The imperative flow then returns its error, or
nullif this flow is not complete or does not support this operation - Since:
- 4.3
-
toCompletableFuture
Converts the existing flow into the completable future.- Returns:
- a
CompletableFuturethat represents the state if this flow.
-