Register now for Android Dev Summit 2019!

Completer

class Completer<T : Any!>
kotlin.Any
   ↳ androidx.concurrent.futures.CallbackToFutureAdapter.Completer

Used to complete the future returned by getFuture

Summary

Public methods

Unit
addCancellationListener(@NonNull runnable: Runnable, @NonNull executor: Executor)

Use to propagate cancellation from the future to whatever operation is using this Completer.

Boolean
set(value: T)

Sets the result of the Future unless the Future has already been cancelled or set.

Boolean

Cancels Future unless the Future has already been cancelled or set.

Boolean
setException(@NonNull t: Throwable)

Sets the failed result of the Future unless the Future has already been cancelled or set.

Protected methods

Unit

Public methods

addCancellationListener

fun addCancellationListener(@NonNull runnable: Runnable, @NonNull executor: Executor): Unit

Use to propagate cancellation from the future to whatever operation is using this Completer.

Will be called when the returned Future is cancelled by Future#cancel(boolean) or this Completer object is garbage collected before the future completes. Not triggered by setCancelled.

set

fun set(value: T): Boolean

Sets the result of the Future unless the Future has already been cancelled or set. When a call to this method returns, the Future is guaranteed to be done.

Parameters
value T: the value to be used as the result
Return
Boolean: true if this attempt completed the Future, false if it was already complete

setCancelled

fun setCancelled(): Boolean

Cancels Future unless the Future has already been cancelled or set. When a call to this method returns, the Future is guaranteed to be done.

Return
Boolean: true if this attempt completed the Future, false if it was already complete

setException

fun setException(@NonNull t: Throwable): Boolean

Sets the failed result of the Future unless the Future has already been cancelled or set. When a call to this method returns, the Future is guaranteed to be done.

Parameters
t Throwable: the exception to be used as the failed result
Return
Boolean: true if this attempt completed the Future, false if it was already complete

Protected methods

finalize

protected fun finalize(): Unit