CallbackToFutureAdapter.Completer


public final class CallbackToFutureAdapter.Completer<T>


Used to complete the future returned by getFuture

Summary

Public methods

void
addCancellationListener(
    @NonNull Runnable runnable,
    @NonNull Executor executor
)

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

boolean
set(T value)

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

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

Protected methods

void

Public methods

addCancellationListener

Added in 1.0.0
public void addCancellationListener(
    @NonNull Runnable runnable,
    @NonNull Executor executor
)

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

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

set

Added in 1.0.0
public boolean set(T value)

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
T value

the value to be used as the result

Returns
boolean

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

setCancelled

Added in 1.0.0
public boolean setCancelled()

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.

Returns
boolean

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

setException

Added in 1.0.0
public boolean setException(@NonNull Throwable t)

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
@NonNull Throwable t

the exception to be used as the failed result

Returns
boolean

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

Protected methods

finalize

Added in 1.0.0
protected void finalize()