invokeAny

abstract suspend fun <T> invokeAny(tasks: MutableCollection<Callable<T>>): T?

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.

Return

the result returned by one of the tasks

Parameters

tasks

the collection of tasks

the type of the values returned from the tasks

Throws

if interrupted while waiting

if tasks or any element task subject to execution is null

if tasks is empty

if no task successfully completes

if tasks cannot be scheduled for execution


abstract suspend fun <T> invokeAny(tasks: MutableCollection<Callable<T>>, timeout: Long, unit: TimeUnit): T

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.

Return

the result returned by one of the tasks

Parameters

tasks

the collection of tasks

timeout

the maximum time to wait

unit

the time unit of the timeout argument

the type of the values returned from the tasks

Throws

if interrupted while waiting

if tasks, or unit, or any element task subject to execution is null

if the given timeout elapses before any task successfully completes

if no task successfully completes

if tasks cannot be scheduled for execution