Class AsyncKt

  • All Implemented Interfaces:

    
    public final class AsyncKt
    
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final static <T extends Any> T await(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 a CompletableFuture<Result<T>>.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • 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 R
        onError - 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 a CompletableFuture<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) or Result.failure(exception)