# CallbackToFutureAdapter.Completer

Artifact: [androidx.concurrent:concurrent-futures](https://developer.android.com/jetpack/androidx/releases/concurrent) [View Source](https://cs.android.com/search?q=file:androidx/concurrent/futures/CallbackToFutureAdapter.java+class:androidx.concurrent.futures.CallbackToFutureAdapter.Completer) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/concurrent#1.0.0)

*** ** * ** ***


```
class CallbackToFutureAdapter.Completer<T>
```

<br />

*** ** * ** ***

Used to complete the future returned by `https://developer.android.com/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter#getFuture(androidx.concurrent.futures.CallbackToFutureAdapter.Resolver<T>)`

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Completer#addCancellationListener(java.lang.Runnable,java.util.concurrent.Executor)(runnable: https://developer.android.com/reference/java/lang/Runnable.html, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Use to propagate cancellation from the future to whatever operation is using this Completer. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Completer#set(T)(value: T!)` Sets the result of the `Future` unless the `Future` has already been cancelled or set. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Completer#setCancelled()()` Cancels `Future` unless the `Future` has already been cancelled or set. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Completer#setException(java.lang.Throwable)(t: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html)` Sets the failed result of the `Future` unless the `Future` has already been cancelled or set. |

| ### Protected functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Completer#finalize()()` |

## Public functions

### addCancellationListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/concurrent#1.0.0)

```
fun addCancellationListener(runnable: Runnable, 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 `https://developer.android.com/reference/java/util/concurrent/Future.html#cancel(boolean)` or this `Completer` object is garbage collected before the future completes. Not triggered by `https://developer.android.com/reference/kotlin/androidx/concurrent/futures/CallbackToFutureAdapter.Completer#setCancelled()`.

### set

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/concurrent#1.0.0)

```
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 |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if this attempt completed the `Future`, false if it was already complete |

### setCancelled

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/concurrent#1.0.0)

```
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.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if this attempt completed the `Future`, false if it was already complete |

### setException

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/concurrent#1.0.0)

```
fun setException(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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html` | the exception to be used as the failed result |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if this attempt completed the `Future`, false if it was already complete |

## Protected functions

### finalize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/concurrent#1.0.0)

```
protected fun finalize(): Unit
```