Class Async<X,​Y>

  • Type Parameters:
    X - Type of input
    Y - Type of output
    All Implemented Interfaces:
    Func<X,​Future<Y>>, Proc<X>

    public final class Async<X,​Y>
    extends Object
    implements Func<X,​Future<Y>>, Proc<X>
    Func that runs in the background.

    If you want your piece of code to be executed in the background, use Async as following:

     int length = new AsyncFunc(
       input -> input.length()
     ).apply("Hello, world!").get();

    There is no thread-safety guarantee.

    Since:
    0.10
    • Constructor Detail

      • Async

        public Async​(Func<X,​Y> fnc)
        Ctor.
        Parameters:
        fnc - The func
      • Async

        public Async​(Func<X,​Y> fnc,
                     ThreadFactory fct)
        Ctor.
        Parameters:
        fnc - The func
        fct - Factory
      • Async

        public Async​(Func<X,​Y> fnc,
                     ExecutorService exec)
        Ctor.
        Parameters:
        fnc - The func
        exec - Executor Service
    • Method Detail

      • apply

        public Future<Y> apply​(X input)
        Description copied from interface: Func
        Apply it.
        Specified by:
        apply in interface Func<X,​Y>
        Parameters:
        input - The argument
        Returns:
        The result
      • exec

        public void exec​(X input)
        Description copied from interface: Proc
        Execute it.
        Specified by:
        exec in interface Proc<X>
        Parameters:
        input - The argument