Tasks

class Tasks


Task utility methods.

Summary

Public functions

java-static TResult!
<TResult> await(task: Task<TResult!>)

Blocks until the specified Task is complete.

java-static TResult!
<TResult> await(task: Task<TResult!>, timeout: Long, unit: TimeUnit)

Blocks until the specified Task is complete.

java-static Task<TResult!>
<TResult> call(callable: Callable<TResult!>)

This function is deprecated.

Use TaskCompletionSource instead, which allows the caller to manage their own Executor.

java-static Task<TResult!>
<TResult> call(executor: Executor, callable: Callable<TResult!>)

This function is deprecated.

Use TaskCompletionSource instead, which allows the caller to manage their own Executor.

java-static Task<TResult!>
<TResult> forCanceled()

Returns a canceled Task.

java-static Task<TResult!>
<TResult> forException(e: Exception)

Returns a completed Task with the specified exception.

java-static Task<TResult!>
<TResult> forResult(result: TResult!)

Returns a completed Task with the specified result.

java-static Task<Void!>
whenAll(tasks: Array<Task<Any!>!>?)

Returns a Task that completes successfully when all of the specified Tasks complete successfully.

java-static Task<Void!>

Returns a Task that completes successfully when all of the specified Tasks complete successfully.

java-static Task<(Mutable)List<Task<Any!>!>!>

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete.

java-static Task<(Mutable)List<Task<Any!>!>!>

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete.

java-static Task<(Mutable)List<Task<Any!>!>!>
whenAllComplete(executor: Executor!, tasks: Array<Task<Any!>!>?)

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete.

java-static Task<(Mutable)List<Task<Any!>!>!>
whenAllComplete(
    executor: Executor!,
    tasks: (Mutable)Collection<Task<Any!>!>?
)

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete.

java-static Task<(Mutable)List<TResult!>!>
<TResult> whenAllSuccess(tasks: Array<Task<Any!>!>?)

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully.

java-static Task<(Mutable)List<TResult!>!>
<TResult> whenAllSuccess(tasks: (Mutable)Collection<Task<Any!>!>?)

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully.

java-static Task<(Mutable)List<TResult!>!>
<TResult> whenAllSuccess(executor: Executor!, tasks: Array<Task<Any!>!>?)

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully.

java-static Task<(Mutable)List<TResult!>!>
<TResult> whenAllSuccess(
    executor: Executor!,
    tasks: (Mutable)Collection<Task<Any!>!>?
)

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully.

java-static Task<T!>!
<T> withTimeout(task: Task<T!>, timeout: Long, unit: TimeUnit)

Returns a new Task which will return a TimeoutException if a result is not returned within the specified time period.

Public functions

await

java-static fun <TResult> await(task: Task<TResult!>): TResult!

Blocks until the specified Task is complete.

Returns
TResult!

the Task's result

Throws
java.util.concurrent.ExecutionException

if the Task fails. getCause will return the original exception.

java.lang.InterruptedException

if an interrupt occurs while waiting for the Task to complete

await

java-static fun <TResult> await(task: Task<TResult!>, timeout: Long, unit: TimeUnit): TResult!

Blocks until the specified Task is complete.

Returns
TResult!

the Task's result

Throws
java.util.concurrent.ExecutionException

if the Task fails. getCause will return the original exception.

java.lang.InterruptedException

if an interrupt occurs while waiting for the Task to complete

java.util.concurrent.TimeoutException

if the specified timeout is reached before the Task completes

call

java-static fun <TResult> call(callable: Callable<TResult!>): Task<TResult!>

Returns a Task that will be completed with the result of the specified Callable.

If a non-Exception throwable is thrown in the callable, the Task will be failed with a RuntimeException whose cause is the original throwable.

The Callable will be called on the main application thread.

call

java-static fun <TResult> call(executor: Executor, callable: Callable<TResult!>): Task<TResult!>

Returns a Task that will be completed with the result of the specified Callable.

If a non-Exception throwable is thrown in the callable, the Task will be failed with a RuntimeException whose cause is the original throwable.

Parameters
executor: Executor

the Executor to use to call the Callable

forCanceled

java-static fun <TResult> forCanceled(): Task<TResult!>

Returns a canceled Task.

forException

java-static fun <TResult> forException(e: Exception): Task<TResult!>

Returns a completed Task with the specified exception.

forResult

java-static fun <TResult> forResult(result: TResult!): Task<TResult!>

Returns a completed Task with the specified result.

whenAll

java-static fun whenAll(tasks: Array<Task<Any!>!>?): Task<Void!>

Returns a Task that completes successfully when all of the specified Tasks complete successfully. Does not accept nulls.

This Task would fail if any of the provided Tasks fail. This Task would be set to canceled if any of the provided Tasks is canceled and no failure is detected.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAll

java-static fun whenAll(tasks: (Mutable)Collection<Task<Any!>!>?): Task<Void!>

Returns a Task that completes successfully when all of the specified Tasks complete successfully. Does not accept nulls.

The returned Task would fail if any of the provided Tasks fail. The returned Task would be set to canceled if any of the provided Tasks is canceled and no failure is detected.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAllComplete

java-static fun whenAllComplete(tasks: Array<Task<Any!>!>?): Task<(Mutable)List<Task<Any!>!>!>

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete. This Task would always succeed even if any of the provided Tasks fail or canceled. Does not accept nulls.

This method execute tasks on the main thread, and can cause stuttering or delay when the main thread is busy. Consider migrating to whenAllComplete where an executor can be specified to use a background thread.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAllComplete

java-static fun whenAllComplete(tasks: (Mutable)Collection<Task<Any!>!>?): Task<(Mutable)List<Task<Any!>!>!>

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete. This Task would always succeed even if any of the provided Tasks fail or canceled. Does not accept nulls.

This method execute tasks on the main thread, and can cause stuttering or delay when the main thread is busy. Consider migrating to whenAllComplete where an executor can be specified to use a background thread.

Throws
java.lang.NullPointerException

if any of the provided

Tasks are null

whenAllComplete

java-static fun whenAllComplete(executor: Executor!, tasks: Array<Task<Any!>!>?): Task<(Mutable)List<Task<Any!>!>!>

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete. This Task would always succeed even if any of the provided Tasks fail or canceled. Does not accept nulls.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAllComplete

java-static fun whenAllComplete(
    executor: Executor!,
    tasks: (Mutable)Collection<Task<Any!>!>?
): Task<(Mutable)List<Task<Any!>!>!>

Returns a Task with a list of Tasks that completes successfully when all of the specified Tasks complete. This Task would always succeed even if any of the provided Tasks fail or canceled. Does not accept nulls.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAllSuccess

java-static fun <TResult> whenAllSuccess(tasks: Array<Task<Any!>!>?): Task<(Mutable)List<TResult!>!>

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully. This Task would fail if any of the provided Tasks fail. Does not accept nulls.

This Task would be set to canceled if any of the provided Tasks is canceled and no failure is detected.

This method execute tasks on the main thread, and can cause stuttering or delay when the main thread is busy. Consider migrating to whenAllSuccess where an executor can be specified to use a background thread.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAllSuccess

java-static fun <TResult> whenAllSuccess(tasks: (Mutable)Collection<Task<Any!>!>?): Task<(Mutable)List<TResult!>!>

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully. This Task would fail if any of the provided Tasks fail. Does not accept nulls.

This Task would be set to canceled if any of the provided Tasks is canceled and no failure is detected.

This method execute tasks on the main thread, and can cause stuttering or delay when the main thread is busy. Consider migrating to whenAllSuccess where an executor can be specified to use a background thread.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAllSuccess

java-static fun <TResult> whenAllSuccess(executor: Executor!, tasks: Array<Task<Any!>!>?): Task<(Mutable)List<TResult!>!>

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully. This Task would fail if any of the provided Tasks fail. Does not accept nulls.

This Task would be set to canceled if any of the provided Tasks is canceled and no failure is detected.

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

whenAllSuccess

java-static fun <TResult> whenAllSuccess(
    executor: Executor!,
    tasks: (Mutable)Collection<Task<Any!>!>?
): Task<(Mutable)List<TResult!>!>

Returns a Task with a list of Task results that completes successfully when all of the specified Tasks complete successfully. This Task would fail if any of the provided Tasks fail. Does not accept nulls.

This Task would be set to canceled if any of the provided Tasks is canceled and no failure is detected.

Parameters
executor: Executor!

the Executor to use to run the Continuation

Throws
java.lang.NullPointerException

if any of the provided Tasks are null

withTimeout

java-static fun <T> withTimeout(task: Task<T!>, timeout: Long, unit: TimeUnit): Task<T!>!

Returns a new Task which will return a TimeoutException if a result is not returned within the specified time period.

Returns
Task<T!>!

A new Task.