Interface AsyncTask<T>


  • public interface AsyncTask<T>
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      static <T> AsyncTask<java.util.List<T>> all​(java.util.List<AsyncTask<T>> tasks)
      Returns an AsyncTask that resolved when all of the provided AsyncTask instances resolve, or fails if any of the provided AsyncTask instances fails.
      static <T> AsyncTask<java.util.List<AsyncTask<T>>> allSettled​(java.util.List<AsyncTask<T>> tasks)
      Returns an AsyncTask that resolves when all of the provided AsyncTask instances have settled (either resolved or failed).
      static <T> AsyncTask<T> any​(java.util.List<AsyncTask<T>> tasks)
      Returns an AsyncTask that resolves as soon as any of the provided AsyncTask instances resolves, or fails if all of the provided AsyncTask instances fail.
      T await()  
      static <T> java.util.List<T> awaitAll​(java.util.List<AsyncTask<T>> tasks)
      Blocks the current thread and awaits all the provided AsyncTask instances to complete and returns a list of their results.
      static <T> java.util.List<AsyncTask<T>> awaitAllSettled​(java.util.List<AsyncTask<T>> tasks)
      Blocks the current thread and awaits all the provided AsyncTask instances to complete (either resolved or failed) and returns a list of their results.
      static <T> T awaitAny​(java.util.List<AsyncTask<T>> tasks)
      Blocks the current thread and awaits any of the provided AsyncTask instances to complete and returns its result.
      void cancel()  
      AsyncTask<T> catchException​(java.util.function.Consumer<java.lang.Throwable> func2)  
      static <T> AsyncTask<T> completed​(T value)
      Returns an already completed AsyncTask with the given value.
      <R> AsyncTask<R> compose​(ThrowableFunction<T,​AsyncTask<R>> func2)  
      static <T> AsyncTask<T> create​(java.util.function.BiConsumer<java.util.function.Consumer<T>,​java.util.function.Consumer<java.lang.Throwable>> func)
      Create an AsyncTask wrapper around some asynchronous code.
      static <T> AsyncTask<T> create​(java.util.function.BiConsumer<java.util.function.Consumer<T>,​java.util.function.Consumer<java.lang.Throwable>> func, AsyncExecutor executor)
      Same as create(BiConsumer) but the function is executed in the provided executor.
      static <T> AsyncTask<T> failed​(java.lang.Throwable error)
      Returns an already failed AsyncTask with the given error.
      boolean isDone()  
      boolean isFailed()  
      boolean isSuccess()  
      <R> AsyncTask<R> then​(ThrowableFunction<T,​R> func2)  
    • Method Detail

      • cancel

        void cancel()
      • isDone

        boolean isDone()
      • isFailed

        boolean isFailed()
      • isSuccess

        boolean isSuccess()
      • await

        T await()
         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • catchException

        AsyncTask<T> catchException​(java.util.function.Consumer<java.lang.Throwable> func2)
      • awaitAll

        static <T> java.util.List<T> awaitAll​(java.util.List<AsyncTask<T>> tasks)
                                       throws java.lang.Exception
        Blocks the current thread and awaits all the provided AsyncTask instances to complete and returns a list of their results. If any of the AsyncTask instances fails, an exception is thrown.
        Type Parameters:
        T - the type of the result
        Parameters:
        tasks - the list of AsyncTask instances
        Returns:
        a list of results
        Throws:
        java.lang.Exception - if any of the AsyncTask instances fails
      • awaitAny

        static <T> T awaitAny​(java.util.List<AsyncTask<T>> tasks)
                       throws java.lang.Exception
        Blocks the current thread and awaits any of the provided AsyncTask instances to complete and returns its result. If all the AsyncTask instances fail, an exception is thrown.
        Type Parameters:
        T - the type of the result
        Parameters:
        tasks - the list of AsyncTask instances
        Returns:
        the result of one of the provided AsyncTask instances
        Throws:
        java.lang.Exception - if all the AsyncTask instances fail
      • awaitAllSettled

        static <T> java.util.List<AsyncTask<T>> awaitAllSettled​(java.util.List<AsyncTask<T>> tasks)
                                                         throws java.lang.Exception
        Blocks the current thread and awaits all the provided AsyncTask instances to complete (either resolved or failed) and returns a list of their results.
        Type Parameters:
        T - the type of the result
        Parameters:
        tasks - the list of AsyncTask instances
        Returns:
        a list of AsyncTask instances that are either resolved or failed
        Throws:
        java.lang.Exception - if the waiting is interrupted
      • all

        static <T> AsyncTask<java.util.List<T>> all​(java.util.List<AsyncTask<T>> tasks)
        Returns an AsyncTask that resolved when all of the provided AsyncTask instances resolve, or fails if any of the provided AsyncTask instances fails.
        Type Parameters:
        T - the type of the result
        Parameters:
        tasks - the list of AsyncTask instances
        Returns:
        an AsyncTask that resolves to a list of results
      • any

        static <T> AsyncTask<T> any​(java.util.List<AsyncTask<T>> tasks)
        Returns an AsyncTask that resolves as soon as any of the provided AsyncTask instances resolves, or fails if all of the provided AsyncTask instances fail.
        Type Parameters:
        T - the type of the result
        Parameters:
        tasks - the list of AsyncTask instances
        Returns:
        an AsyncTask that resolves to the result of one of the provided AsyncTask instances
      • allSettled

        static <T> AsyncTask<java.util.List<AsyncTask<T>>> allSettled​(java.util.List<AsyncTask<T>> tasks)
        Returns an AsyncTask that resolves when all of the provided AsyncTask instances have settled (either resolved or failed).
        Type Parameters:
        T - the type of the result
        Parameters:
        tasks - the list of AsyncTask instances
        Returns:
        an AsyncTask that resolves to a list of AsyncTask instances that are either resolved or failed
      • completed

        static <T> AsyncTask<T> completed​(T value)
        Returns an already completed AsyncTask with the given value.
        Type Parameters:
        T - the type of the result
        Parameters:
        value - the value to complete the AsyncTask with
        Returns:
        an already completed AsyncTask
      • failed

        static <T> AsyncTask<T> failed​(java.lang.Throwable error)
        Returns an already failed AsyncTask with the given error.
        Type Parameters:
        T - the type of the result
        Parameters:
        error - the error to fail the AsyncTask with
        Returns:
        an already failed AsyncTask
      • create

        static <T> AsyncTask<T> create​(java.util.function.BiConsumer<java.util.function.Consumer<T>,​java.util.function.Consumer<java.lang.Throwable>> func)
        Create an AsyncTask wrapper around some asynchronous code.
        Type Parameters:
        T - the type of the result
        Parameters:
        func - the function that receives two parameters: a resolve function and a reject function. The resolve function must be called when the asynchronous operation completes successfully, and the reject function must be called when the asynchronous operation fails.
        Returns:
        an AsyncTask that represents the asynchronous operation
      • create

        static <T> AsyncTask<T> create​(java.util.function.BiConsumer<java.util.function.Consumer<T>,​java.util.function.Consumer<java.lang.Throwable>> func,
                                       AsyncExecutor executor)
        Same as create(BiConsumer) but the function is executed in the provided executor.
        Type Parameters:
        T - the type of the result
        Parameters:
        func - the function that receives two parameters: a resolve function and a reject function. The resolve function must be called when the asynchronous operation completes successfully, and the reject function must be called when the asynchronous operation fails.
        executor - the executor to run the function in
        Returns:
        an AsyncTask that represents the asynchronous operation