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))
      .thenApply(response::send);

     // use async to obtain a Multi (from a method returning List of strings)
     Multi<String> stringMulti = async.invoke(this::syncList)
                 .flatMap(Multi::create);
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Fluent API Builder for Async.
  • Method Summary

    Modifier and Type
    Method
    Description
    A new builder to build a customized Async instance.
    static Async
    Async with default executor service.
    <T> Single<T>
    invoke(Supplier<T> supplier)
    Invoke a synchronous operation asynchronously.
  • Method Details

    • 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
      Parameters:
      supplier - supplier of value (may be a method reference)
      Returns:
      a Single that is a "promise" of the future result
    • create

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

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