org.hibernate.search.util.impl

## Class Futures

- java.lang.Object
- - org.hibernate.search.util.impl.Futures

-     public final class Futures
      extends Object

  Author:
    Yoann Rodiere

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> BiConsumer<T,Throwable>` | `copyHandler(CompletableFuture<T> copyFuture)` Creates a future handler that will copy the state of the handled future to the given future.
    `static <T> CompletableFuture<T>` | `create(Supplier<CompletableFuture<T>> initiator)` Create a `CompletableFuture` using the given supplier.
    `static <T> BiConsumer<T,Throwable>` | `handler(BiConsumer<T,Throwable> delegate)` Creates a future handler that will delegate to the given `BiConsumer` after having unwrapped the throwable passed as input if it is a `CompletionException`.
    `static <T,R> BiFunction<T,Throwable,R>` | `handler(BiFunction<T,Throwable,R> delegate)` Creates a future handler that will delegate to the given `BiFunction` after having unwrapped the throwable passed as input if it is a `CompletionException`.
    `static <T> Function<Throwable,T>` | `handler(Function<Throwable,T> delegate)` Creates a future handler that will delegate to the given `Function` after having unwrapped the throwable passed as input if it is a `CompletionException`.
    `static <T,R> Function<T,CompletionStage<R>>` | `safeComposer(Function<? super T,? extends CompletionStage<R>> delegate)` Creates a composition function that will delegate to the given `Function` but will catch any exception during composition to return a future completed exceptionally.
    `static <T> CompletableFuture<T>` | `whenCompleteExecute(CompletableFuture<?> self, Supplier<? extends CompletionStage<T>> action)` Compose the given future with another as soon as it's complete, regardless of errors, and return a completable future that will take errors of both parent futures into account (using `Throwable.addSuppressed(Throwable)` if need be).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### create

          public static <T> CompletableFuture<T> create(Supplier<CompletableFuture<T>> initiator)

      Create a `CompletableFuture` using the given supplier.

      This method is guaranteed to never throw any exception: any exception thrown by the given supplier will instead complete the resulting future `exceptionally`.

      This is useful in particular if you want to handle errors during the `CompletableFuture` creation the same way as errors thrown during post-processing operations (for instance operations passed to `CompletableFuture.thenApply(Function)`).

      Parameters:
        `initiator` - A supplier that will initiate (synchronously) the asynchronous operation.
      Returns:
        A `CompletableFuture` wrapping the result of both the initiation and execution of the operation.

    - #### handler

          public static <T> Function<Throwable,T> handler(Function<Throwable,T> delegate)

      Creates a future handler that will delegate to the given `Function` after having unwrapped the throwable passed as input if it is a `CompletionException`.

      This method is meant to be used in conjunction with `CompletableFuture.exceptionally(Function)`.

      Parameters:
        `delegate` - The exception function to delegate to
      Returns:
        The new, delegating exception function.

    - #### handler

          public static <T,R> BiFunction<T,Throwable,R> handler(BiFunction<T,Throwable,R> delegate)

      Creates a future handler that will delegate to the given `BiFunction` after having unwrapped the throwable passed as input if it is a `CompletionException`.

      This method is meant to be used in conjunction with `CompletableFuture.handle(BiFunction)`.

      Parameters:
        `delegate` - The handler to delegate to
      Returns:
        The new, delegating handler.

    - #### handler

          public static <T> BiConsumer<T,Throwable> handler(BiConsumer<T,Throwable> delegate)

      Creates a future handler that will delegate to the given `BiConsumer` after having unwrapped the throwable passed as input if it is a `CompletionException`.

      This method is meant to be used in conjunction with `CompletableFuture.whenComplete(BiConsumer)`.

      Parameters:
        `delegate` - The handler to delegate to
      Returns:
        The new, delegating handler.

    - #### copyHandler

          public static <T> BiConsumer<T,Throwable> copyHandler(CompletableFuture<T> copyFuture)

      Creates a future handler that will copy the state of the handled future to the given future.

      This method is meant to be used in conjunction with `CompletableFuture.whenComplete(BiConsumer)`.

      Parameters:
        `copyFuture` - The future to copy to
      Returns:
        the copy handler

    - #### safeComposer

          public static <T,R> Function<T,CompletionStage<R>> safeComposer(Function<? super T,? extends CompletionStage<R>> delegate)

      Creates a composition function that will delegate to the given `Function` but will catch any exception during composition to return a future completed exceptionally.

      This method is meant to be used in conjunction with `CompletableFuture.thenCompose(Function)`. It is useful in particular when you want to apply the same error handling to the composition function and to the resulting future.

      Parameters:
        `delegate` - The composition function to delegate to.
      Returns:
        The new, delegating composition function .

    - #### whenCompleteExecute

          public static <T> CompletableFuture<T> whenCompleteExecute(CompletableFuture<?> self,
                                                                     Supplier<? extends CompletionStage<T>> action)

      Compose the given future with another as soon as it's complete, regardless of errors, and return a completable future that will take errors of both parent futures into account (using `Throwable.addSuppressed(Throwable)` if need be).
      Parameters:
        `self` - The future to wait for before launching the next one
        `action` - the composition consumer
      Returns:
        A completable future that will be complete once `self` finished executing and `action` and its resulting future finished executing.

Copyright © 2006-2017 Red Hat, Inc. All Rights Reserved