Package 

Object Task.Companion

    • Method Detail

      • delay

         final Task<Void> delay(Long delay)

        Creates a task that completes after a time delay.

        Parameters:
        delay - The number of milliseconds to wait before completing the returned task.
      • delay

         final Task<Void> delay(Long delay, CancellationToken cancellationToken)

        Creates a task that completes after a time delay.

        Parameters:
        delay - The number of milliseconds to wait before completing the returned task.
        cancellationToken - The optional cancellation token that will be checked prior to completing the returned task.
      • callInBackground

         final <TResult extends Any> Task<TResult> callInBackground(Callable<TResult> callable)

        Invokes the callable on a background thread, returning a Task to represent the operation.

        If you want to cancel the resulting Task throw a Exception from the callable.

      • call

         final <TResult extends Any> Task<TResult> call(Callable<TResult> callable, Executor executor)

        Invokes the callable using the given executor, returning a Task to represent the operation.

        If you want to cancel the resulting Task throw a Exception from the callable.

      • call

         final <TResult extends Any> Task<TResult> call(Callable<TResult> callable)

        Invokes the callable on the current thread, producing a Task.

        If you want to cancel the resulting Task throw a Exception from the callable.

      • whenAnyResult

         final <TResult extends Any> Task<Task<TResult>> whenAnyResult(Collection<Task<TResult>> tasks)

        Creates a task that will complete when any of the supplied tasks have completed.

        The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the completed state with its result set to the first task to complete. This is true even if the first task to complete ended in the canceled or faulted state.

        Parameters:
        tasks - The tasks to wait on for completion.
      • whenAny

         final Task<Task<?>> whenAny(Collection<Task<?>> tasks)

        Creates a task that will complete when any of the supplied tasks have completed.

        The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the completed state with its result set to the first task to complete. This is true even if the first task to complete ended in the canceled or faulted state.

        Parameters:
        tasks - The tasks to wait on for completion.
      • whenAllResult

         final <TResult extends Any> Task<List<TResult>> whenAllResult(Collection<Task<TResult>> tasks)

        Creates a task that completes when all of the provided tasks are complete.

        If any of the supplied tasks completes in a faulted state, the returned task will also complete in a faulted state, where its exception will resolve to that Exception if a single task fails or an AggregateException of all the Exceptions if multiple tasks fail.

        If none of the supplied tasks faulted but at least one of them was cancelled, the returned task will end as cancelled.

        If none of the tasks faulted and none of the tasks were cancelled, the resulting task will end completed. The result of the returned task will be set to a list containing all of the results of the supplied tasks in the same order as they were provided (e.g. if the input tasks collection contained t1, t2, t3, the output task's result will return an List&lt;TResult&gt; where list.get(0) == t1.getResult(), list.get(1) == t2.getResult(), and list.get(2) == t3.getResult()).

        If the supplied collection contains no tasks, the returned task will immediately transition to a completed state before it's returned to the caller. The returned List&lt;TResult&gt; will contain 0 elements.

        Parameters:
        tasks - The tasks that the return value will wait for before completing.
      • whenAll

         final Task<Void> whenAll(Collection<Task<?>> tasks)

        Creates a task that completes when all of the provided tasks are complete.

        If any of the supplied tasks completes in a faulted state, the returned task will also complete in a faulted state, where its exception will resolve to that [ ] if a single task fails or an AggregateException of all the [ ]s if multiple tasks fail.

        If none of the supplied tasks faulted but at least one of them was cancelled, the returned task will end as cancelled.

        If none of the tasks faulted and none of the tasks were canceled, the resulting task will end in the completed state.

        If the supplied collection contains no tasks, the returned task will immediately transition to a completed state before it's returned to the caller.

        Parameters:
        tasks - The tasks that the return value will wait for before completing.