Module lettuce.core

Class Futures

java.lang.Object
io.lettuce.core.internal.Futures

public abstract class Futures
extends Object
Utility methods for Future handling. This class is part of the internal API and may change without further notice.
Since:
5.1
Author:
Mark Paluch
  • Method Details

    • allOf

      public static CompletableFuture<Void> allOf​(Collection<? extends CompletionStage<?>> stages)
      Create a composite CompletableFuture is composed from the given stages.
      Parameters:
      stages - must not be null.
      Returns:
      the composed CompletableFuture.
      Since:
      5.1.1
    • failed

      public static <T> CompletableFuture<T> failed​(Throwable throwable)
      Create a CompletableFuture that is completed exceptionally with throwable.
      Parameters:
      throwable - must not be null.
      Returns:
      the exceptionally completed CompletableFuture.
    • toCompletionStage

      public static <V> CompletionStage<V> toCompletionStage​(Future<V> future)
      Adapt Netty's ChannelFuture emitting a Void result.
      Parameters:
      future - the ChannelFuture to adapt.
      Returns:
      the CompletableFuture.
      Since:
      6.0
    • adapt

      public static <V> void adapt​(Future<V> source, CompletableFuture<V> target)
      Adapt Netty's Future emitting a value result into a CompletableFuture.
      Parameters:
      source - source Future emitting signals.
      target - target CompletableFuture.
      Since:
      6.0
    • await

      public static boolean await​(Duration timeout, Future<?> future)
      Wait until future is complete or the supplied timeout is reached.
      Parameters:
      timeout - Maximum time to wait for futures to complete.
      future - Future to wait for.
      Returns:
      true if future completes in time, otherwise false
      Since:
      6.0
    • await

      public static boolean await​(long timeout, TimeUnit unit, Future<?> future)
      Wait until future is complete or the supplied timeout is reached.
      Parameters:
      timeout - Maximum time to wait for futures to complete.
      unit - Unit of time for the timeout.
      future - Future to wait for.
      Returns:
      true if future completes in time, otherwise false
      Since:
      6.0
    • awaitAll

      public static boolean awaitAll​(Duration timeout, Future<?>... futures)
      Wait until futures are complete or the supplied timeout is reached.
      Parameters:
      timeout - Maximum time to wait for futures to complete.
      futures - Futures to wait for.
      Returns:
      true if all futures complete in time, otherwise false
      Since:
      6.0
    • awaitAll

      public static boolean awaitAll​(long timeout, TimeUnit unit, Future<?>... futures)
      Wait until futures are complete or the supplied timeout is reached.
      Parameters:
      timeout - Maximum time to wait for futures to complete.
      unit - Unit of time for the timeout.
      futures - Futures to wait for.
      Returns:
      true if all futures complete in time, otherwise false
    • awaitOrCancel

      public static <T> T awaitOrCancel​(RedisFuture<T> cmd, long timeout, TimeUnit unit)
      Wait until futures are complete or the supplied timeout is reached. Commands are canceled if the timeout is reached but the command is not finished.
      Type Parameters:
      T - Result type
      Parameters:
      cmd - Command to wait for
      timeout - Maximum time to wait for futures to complete
      unit - Unit of time for the timeout
      Returns:
      Result of the command.
      Since:
      6.0