Class AsyncKt
-
- All Implemented Interfaces:
public final class AsyncKt
-
-
Method Summary
Modifier and Type Method Description final static <T extends Any> Tawait(CompletableFuture<T> $self)Awaits for completion of this CompletableFuture without blocking a thread. final static <T extends Any, R extends Any> CompletableFuture<R>mapWithCancellation(CompletableFuture<T> $self, Function1<T, R> onSuccess, Function1<Throwable, R> onError)Transforms a CompletableFuture<T> into a CompletableFuture<R> with proper bidirectional cancellation. final static <T extends Any> CompletableFuture<Result<T>>toResultFuture(CompletableFuture<T> $self)Converts a CompletableFuture<T>to aCompletableFuture<Result<T>>.-
-
Method Detail
-
await
final static <T extends Any> T await(CompletableFuture<T> $self)
Awaits for completion of this CompletableFuture without blocking a thread.
This suspending function is cancellable. If the coroutine is cancelled while this function is suspended, the future will be cancelled as well.
- Returns:
The result value of the CompletableFuture
-
mapWithCancellation
final static <T extends Any, R extends Any> CompletableFuture<R> mapWithCancellation(CompletableFuture<T> $self, Function1<T, R> onSuccess, Function1<Throwable, R> onError)
Transforms a CompletableFuture<T> into a CompletableFuture<R> with proper bidirectional cancellation.
This helper wraps a native future and transforms its result, while ensuring that:
Success values are transformed using the provided mapper
CancellationExceptions propagate as cancellations (not completions)
Other exceptions are transformed using the error mapper
Cancellation of the outer future cancels the inner future
- Parameters:
onSuccess- Function to transform success values from T to RonError- Function to transform non-cancellation exceptions to R- Returns:
A new CompletableFuture<R> with bidirectional cancellation support
-
toResultFuture
final static <T extends Any> CompletableFuture<Result<T>> toResultFuture(CompletableFuture<T> $self)
Converts a
CompletableFuture<T>to aCompletableFuture<Result<T>>.This helper function wraps the result of a CompletableFuture in a Result, catching any exceptions and converting them to
Result.failure().Uses libsignal's chaining mechanism to ensure proper bidirectional cancellation propagation for long async operations, like network requests.
- Returns:
A new CompletableFuture that completes with
Result.success(value)orResult.failure(exception)
-
-
-
-