FutureTask

open class FutureTask<V> : RunnableFuture<V>

A cancellable asynchronous computation. This class provides a base implementation of Future, with methods to start and cancel a computation, query to see if the computation is complete, and retrieve the result of the computation. The result can only be retrieved when the computation has completed; the get methods will block if the computation has not yet completed. Once the computation has completed, the computation cannot be restarted or cancelled (unless the computation is invoked using runAndReset).

A FutureTask can be used to wrap a CommonCallable or Runnable object. Because FutureTask implements Runnable, a FutureTask can be submitted to an CoroutineScope for execution.

In addition to serving as a standalone class, this class provides protected functionality that may be useful when creating customized task classes.

Parameters

The result type returned by this FutureTask's `get` methods

Constructors

Link copied to clipboard
constructor(callable: Callable<V>)

Creates a FutureTask that will, upon running, execute the given Callable.

constructor(runnable: Runnable, result: V?)

Creates a FutureTask that will, upon running, execute the given Runnable, and arrange that get will return the given result on successful completion.

Types

Link copied to clipboard

Functions

Link copied to clipboard
open override fun cancel(mayInterruptIfRunning: Boolean): Boolean

Attempts to cancel execution of this task.

Link copied to clipboard
Link copied to clipboard
open suspend override fun get(): V
suspend fun get(timeout: Long, unit: TimeUnit): V
Link copied to clipboard
open override fun isCancelled(): Boolean

Returns true if the task was cancelled before completion.

Link copied to clipboard
open override fun isDone(): Boolean

Returns true if the task completed (either successfully, with an exception, or was cancelled).

Link copied to clipboard
fun resultNow(): V
Link copied to clipboard
open override fun run()
Link copied to clipboard
suspend fun state(): FutureTask.State
Link copied to clipboard
open override fun toString(): String

Returns a string representation of this FutureTask.