Interface ExecutionFlow<T>

Type Parameters:
T - The flow type
All Known Subinterfaces:
CompletableFutureExecutionFlow<T>, DelayedExecutionFlow<T>, ImperativeExecutionFlow<T>, ReactiveExecutionFlow<T>

@Internal public interface ExecutionFlow<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 Details

    • just

      static <K> @NonNull ExecutionFlow<K> just(@Nullable K value)
      Create a simple flow representing a value.
      Type Parameters:
      K - The value type
      Parameters:
      value - The value
      Returns:
      a new flow
    • error

      static <K> @NonNull ExecutionFlow<K> error(@NonNull Throwable e)
      Create a simple flow representing an error.
      Type Parameters:
      K - The value type
      Parameters:
      e - The exception
      Returns:
      a new flow
    • empty

      static <T> @NonNull ExecutionFlow<T> empty()
      Create a simple flow representing an empty state.
      Type Parameters:
      T - The flow value type
      Returns:
      a new flow
    • async

      static <T> @NonNull ExecutionFlow<T> async(@NonNull Executor executor, @NonNull Supplier<? extends ExecutionFlow<T>> supplier)
      Create a flow by invoking a supplier asynchronously.
      Type Parameters:
      T - The flow value type
      Parameters:
      executor - The executor
      supplier - The supplier
      Returns:
      a new flow
    • map

      <R> @NonNull ExecutionFlow<R> map(@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

      <R> @NonNull ExecutionFlow<R> flatMap(@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

      <R> @NonNull ExecutionFlow<R> then(@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 ExecutionFlow<T> onErrorResume(@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 ExecutionFlow<T> putInContext(@NonNull String key, @NonNull Object value)
      Store a contextual value.
      Parameters:
      key - The key
      value - The value
      Returns:
      a new flow
    • putInContextIfAbsent

      default @NonNull ExecutionFlow<T> putInContextIfAbsent(@NonNull String key, @NonNull Object value)
      Store a contextual value if it is absent.
      Parameters:
      key - The key
      value - The value
      Returns:
      a new flow
      Since:
      4.8.0
    • onComplete

      void onComplete(@NonNull BiConsumer<? super T,Throwable> fn)
      Invokes a provided function when the flow is resolved, or immediately if it is already done.
      Parameters:
      fn - The function
    • completeTo

      void completeTo(@NonNull CompletableFuture<T> completableFuture)
      Completes the flow to the completable future.
      Parameters:
      completableFuture - The completable future
      Since:
      4.8
    • timeout

      default @NonNull ExecutionFlow<T> timeout(@NonNull Duration timeout, @NonNull ScheduledExecutorService scheduler, @Nullable BiConsumer<T,Throwable> onDiscard)
      Create a new ExecutionFlow that either returns the same result or, if the timeout expires before the result is received, a TimeoutException.
      Parameters:
      timeout - The timeout
      scheduler - Scheduler to schedule the timeout task
      onDiscard - An optional consumer to be called on the value of this flow if the flow completes after the timeout has expired and thus the value is discarded
      Returns:
      A new flow that will produce either the same value or a TimeoutException
    • tryComplete

      @Nullable ImperativeExecutionFlow<T> tryComplete()
      Create an ImperativeExecutionFlow from this execution flow, if possible. The flow will have its result immediately available.
      Returns:
      The imperative flow, or null if this flow is not complete or does not support this operation
    • tryCompleteValue

      default @Nullable T tryCompleteValue()
      Alternative to tryComplete() which will unwrap the flow's value.
      Returns:
      The imperative flow then returns its value, or null if this flow is not complete or does not support this operation
      Since:
      4.3
    • tryCompleteError

      default @Nullable Throwable tryCompleteError()
      Alternative to tryComplete() which will unwrap the flow's error.
      Returns:
      The imperative flow then returns its error, or null if this flow is not complete or does not support this operation
      Since:
      4.3
    • toCompletableFuture

      default @NonNull CompletableFuture<T> toCompletableFuture()
      Converts the existing flow into the completable future.
      Returns:
      a CompletableFuture that represents the state if this flow.
    • cancel

      default void cancel()
      Send an optional hint to the upstream producer that the result of this flow is no longer needed and can be discarded. This is an optional operation, and has no effect if the flow has already completed. After a cancellation, a flow might never complete.

      If this flow contains a resource that needs to be cleaned up (e.g. an InputStream), the caller should still add a completion listener for cleanup, in case the upstream producer does not support cancellation or has already submitted the result.

      Since:
      4.8.0