Interface Task<T>

  • Type Parameters:
    T - result type
    All Known Subinterfaces:
    Task.SyncTask<T>
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    interface Task<T>
    Represents a possibly asynchronous unit of work, called "Task".

    A Task is a function that takes an instance of Task.Complete and returns nothing.

    Complete is a handler that needs to be actively called to complete the Task.

    
     Callable<T> worker = ...;
     Future<T> result = Future.run(complete -> complete.with(Try.of(worker::call)));
     
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  Task.Complete<T>
      Completes a task.
      static interface  Task.SyncTask<T>
      A marker interface for synchronous tasks that are executed immediately.
    • Method Detail

      • run

        void run​(Task.Complete<T> complete)
          throws java.lang.Throwable
        Runs the task. Non-fatal errors are catched by a Future.
        Parameters:
        complete - a function that completes this task
        Throws:
        java.lang.Throwable - if an error occurs