Interface Async

  • public interface Async
    Support for asynchronous execution of synchronous (blocking) calls. While this does not miraculously make a synchronous call non-blocking, it at least moves the blocking calls to a separate executor service, degrading the service gracefully.

    Example of usage:

         // async instance with default executor service
         Async async = Async.create();
         // call a method with no parameters
         Single<String> result = async.invoke(this::slowSync);
         // call a method with parameters
         async.invoke(() -> processRequest(request))
         // use async to obtain a Multi (from a method returning List of strings)
         Multi<String> stringMulti = async.invoke(this::syncList)
    • Method Detail

      • invoke

        <T> Single<T> invoke​(Supplier<T> supplier)
        Invoke a synchronous operation asynchronously. This method never throws an exception. Any exception is returned via the Single result.
        Type Parameters:
        T - type of returned value
        supplier - supplier of value (may be a method reference)
        a Single that is a "promise" of the future result
      • create

        static Async create()
        Async with default executor service.
        a default async instance
      • builder

        static Async.Builder builder()
        A new builder to build a customized Async instance.
        a new builder