Package com.launchdarkly.sdk.android
Class LDFutures
java.lang.Object
com.launchdarkly.sdk.android.LDFutures
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 TypeMethodDescriptionstatic <T> com.launchdarkly.sdk.android.LDAwaitFuture<T>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.
-
Method Details
-
fromFuture
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 anyFuture(API-level safe).- Type Parameters:
T- common result type; useObjectwhen mixing futures of different types- Parameters:
futures- the futures to race (null or empty returns a future that never completes)- Returns:
- an
LDAwaitFuturethat completes with the first result (or the first exception)
-