# Operation

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

*** ** * ** ***

<br />

```
public interface Operation
```

<br />

*** ** * ** ***

An object that provides information about the execution of an asynchronous command being performed by `https://developer.android.com/reference/androidx/work/WorkManager`. Operations are generally tied to enqueue or cancel commands; when you call one of those commands, they occur asynchronously. You can observe or await these commands by using the returned Operation.

## Summary

| ### Nested types |
|---|
| `public abstract class https://developer.android.com/reference/androidx/work/Operation.State` The lifecycle state of an `https://developer.android.com/reference/androidx/work/Operation`. |
| `public final class https://developer.android.com/reference/androidx/work/Operation.State.FAILURE extends https://developer.android.com/reference/androidx/work/Operation.State` This represents an `https://developer.android.com/reference/androidx/work/Operation` which has failed. |
| `public final class https://developer.android.com/reference/androidx/work/Operation.State.IN_PROGRESS extends https://developer.android.com/reference/androidx/work/Operation.State` This represents an `https://developer.android.com/reference/androidx/work/Operation` which is in progress. |
| `public final class https://developer.android.com/reference/androidx/work/Operation.State.SUCCESS extends https://developer.android.com/reference/androidx/work/Operation.State` This represents an `https://developer.android.com/reference/androidx/work/Operation` which is successful. |

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/work/Operation.State.SUCCESS>` | `https://developer.android.com/reference/androidx/work/Operation#getResult()()` Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` for the terminal state of the `https://developer.android.com/reference/androidx/work/Operation`. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LiveData<https://developer.android.com/reference/androidx/work/Operation.State>` | `https://developer.android.com/reference/androidx/work/Operation#getState()()` Gets a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of the Operation `https://developer.android.com/reference/androidx/work/Operation.State`. |

| ### Extension functions |
|---|---|
| `default final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Operation.State.SUCCESS` | `https://developer.android.com/reference/androidx/work/OperationKt.https://developer.android.com/reference/androidx/work/Operation#(androidx.work.Operation).await()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Operation receiver)` Awaits an `https://developer.android.com/reference/androidx/work/Operation` without blocking a thread. |

## Public methods

### getResult

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

```
abstract @NonNull ListenableFuture<Operation.State.SUCCESS> getResult()
```

Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` for the terminal state of the `https://developer.android.com/reference/androidx/work/Operation`. This will only resolve with a `https://developer.android.com/reference/androidx/work/Operation.State.SUCCESS`. The `https://developer.android.com/reference/androidx/work/Operation.State.FAILURE` state will come through as a `https://developer.android.com/reference/java/lang/Throwable.html` on the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html`. `https://developer.android.com/reference/androidx/work/Operation.State.IN_PROGRESS` will never be reported as it's not a terminal state.

Call `https://developer.android.com/reference/java/util/concurrent/Future.html#get()` to block until the `https://developer.android.com/reference/androidx/work/Operation` reaches a terminal state.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/work/Operation.State.SUCCESS>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` with information about `https://developer.android.com/reference/androidx/work/Operation`'s `https://developer.android.com/reference/androidx/work/Operation.State.SUCCESS` state. |

### getState

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

```
abstract @NonNull LiveData<Operation.State> getState()
```

Gets a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of the Operation `https://developer.android.com/reference/androidx/work/Operation.State`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LiveData<https://developer.android.com/reference/androidx/work/Operation.State>` | A `https://developer.android.com/reference/androidx/lifecycle/LiveData` of the Operation `https://developer.android.com/reference/androidx/work/Operation.State`; you must use `https://developer.android.com/reference/androidx/lifecycle/LiveData#observe(androidx.lifecycle.LifecycleOwner,androidx.lifecycle.Observer<? super T>)` to receive updates |

## Extension functions

### OperationKt.await

Artifact: [androidx.work:work-runtime](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/Operation.kt+function:await)

```
default final @NonNull Operation.State.SUCCESS OperationKt.await(@NonNull Operation receiver)
```

Awaits an `https://developer.android.com/reference/androidx/work/Operation` without blocking a thread.

This method returns the terminal state of the \[Operation\] which is \[Operation.State.SUCCESS\] or throws a \[Throwable\] that represents why the \[Operation\] failed.