Operation

public interface Operation


An object that provides information about the execution of an asynchronous command being performed by 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 Operation.State

The lifecycle state of an Operation.

public final class Operation.State.FAILURE extends Operation.State

This represents an Operation which has failed.

public final class Operation.State.IN_PROGRESS extends Operation.State

This represents an Operation which is in progress.

public final class Operation.State.SUCCESS extends Operation.State

This represents an Operation which is successful.

Public methods

abstract @NonNull ListenableFuture<Operation.State.SUCCESS>

Gets a ListenableFuture for the terminal state of the Operation.

abstract @NonNull LiveData<Operation.State>

Gets a LiveData of the Operation State.

Extension functions

default final @NonNull Operation.State.SUCCESS

Awaits an Operation without blocking a thread.

Public methods

getResult

Added in 1.0.0
abstract @NonNull ListenableFuture<Operation.State.SUCCESSgetResult()

Gets a ListenableFuture for the terminal state of the Operation. This will only resolve with a State.SUCCESS. The State.FAILURE state will come through as a Throwable on the ListenableFuture. State.IN_PROGRESS will never be reported as it's not a terminal state.

Call get to block until the Operation reaches a terminal state.

getState

Added in 1.0.0
abstract @NonNull LiveData<Operation.StategetState()

Gets a LiveData of the Operation State.

Returns
@NonNull LiveData<Operation.State>

A LiveData of the Operation State; you must use observe to receive updates

Extension functions

OperationKt.await

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

Awaits an 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.