Class LDFutures

java.lang.Object
com.launchdarkly.sdk.android.LDFutures

public final class LDFutures extends Object
Helpers for asynchronous results, including settable futures and anyOf for racing completions.

Use this when you need CompletableFuture-like behavior (e.g. anyOf) on all Android API levels. LDAwaitFuture is a settable Future; anyOf(Future[]) returns when the first of several futures completes.

  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> com.launchdarkly.sdk.android.LDAwaitFuture<T>
    anyOf(Future<? extends T>... futures)
    Returns a future that completes when the first of the given futures completes.
    static <T> com.launchdarkly.sdk.android.LDAwaitFuture<T>
    fromFuture(Future<T> future)
    Converts any Future to an LDAwaitFuture that completes when the given future completes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • fromFuture

      public static <T> com.launchdarkly.sdk.android.LDAwaitFuture<T> fromFuture(Future<T> future)
      Converts any Future to an LDAwaitFuture that completes when the given future completes. If the future is already an LDAwaitFuture, returns it as-is.

      If the future is already done, it is resolved synchronously without spawning a thread. Otherwise, a pooled daemon thread blocks on the future until it completes.

      Type Parameters:
      T - result type
      Parameters:
      future - the future to wrap
      Returns:
      an LDAwaitFuture that completes with the same result or exception
    • anyOf

      @SafeVarargs public static <T> com.launchdarkly.sdk.android.LDAwaitFuture<T> anyOf(Future<? extends T>... futures)
      Returns a future that completes when the first of the given futures completes. Equivalent to CompletableFuture.anyOf. Works with any Future (API-level safe).
      Type Parameters:
      T - common result type; use Object when mixing futures of different types
      Parameters:
      futures - the futures to race (null or empty returns a future that never completes)
      Returns:
      an LDAwaitFuture that completes with the first result (or the first exception)