WorkContinuation
abstract class WorkContinuation
A class that allows you to chain together OneTimeWorkRequests. WorkContinuations allow the user to create arbitrary acyclic graphs of work dependencies. You can add dependent work to a WorkContinuation by invoking then or its variants. This returns a new WorkContinuation.
To construct more complex graphs, combine or its variants can be used to return a WorkContinuation with the input WorkContinuations as prerequisites. To create a graph like this:
A C | | B D | | +-------+ | E
WorkContinuation left = workManager.beginWith(A).then(B); WorkContinuation right = workManager.beginWith(C).then(D); WorkContinuation final = WorkContinuation.combine(Arrays.asList(left, right)).then(E); final.enqueue();
enqueue to inform WorkManager to actually enqueue the work graph. As usual, enqueues are asynchronous - you can observe or block on the returned Operation if you need to be informed about its completion.
Because of the fluent nature of this class, its existence should be invisible in most cases.
Summary
Public constructors |
|---|
Public functions |
|
|---|---|
java-static WorkContinuation |
combine(continuations: (Mutable)List<WorkContinuation!>)Combines multiple |
abstract Operation |
enqueue()Enqueues the instance of |
abstract ListenableFuture<(Mutable)List<WorkInfo!>!> |
Returns a |
abstract LiveData<(Mutable)List<WorkInfo!>!> |
Returns a |
abstract WorkContinuation |
then(work: (Mutable)List<OneTimeWorkRequest!>)Adds new |
WorkContinuation |
then(work: OneTimeWorkRequest)Adds new |
Public constructors
Public functions
combine
java-static fun combine(continuations: (Mutable)List<WorkContinuation!>): WorkContinuation
Combines multiple WorkContinuations as prerequisites for a new WorkContinuation to allow for complex chaining. For example, to create a graph like this:
A C | | B D | | +-------+ | E
WorkContinuation left = workManager.beginWith(A).then(B); WorkContinuation right = workManager.beginWith(C).then(D); WorkContinuation final = WorkContinuation.combine(Arrays.asList(left, right)).then(E); final.enqueue();
| Parameters | |
|---|---|
continuations: (Mutable)List<WorkContinuation!> |
One or more |
| Returns | |
|---|---|
WorkContinuation |
A |
enqueue
abstract fun enqueue(): Operation
Enqueues the instance of WorkContinuation on the background thread.
getWorkInfos
abstract fun getWorkInfos(): ListenableFuture<(Mutable)List<WorkInfo!>!>
Returns a ListenableFuture of a List of WorkInfos that provides information about the status of each OneTimeWorkRequest in this WorkContinuation, as well as their prerequisites.
| Returns | |
|---|---|
ListenableFuture<(Mutable)List<WorkInfo!>!> |
A |
getWorkInfosLiveData
abstract fun getWorkInfosLiveData(): LiveData<(Mutable)List<WorkInfo!>!>
Returns a LiveData list of WorkInfos that provide information about the status of each OneTimeWorkRequest in this WorkContinuation, as well as their prerequisites. If the state or outputs of any of the work changes, any attached Observers will trigger.
then
abstract fun then(work: (Mutable)List<OneTimeWorkRequest!>): WorkContinuation
Adds new OneTimeWorkRequest items that depend on the successful completion of all previously added OneTimeWorkRequests.
| Parameters | |
|---|---|
work: (Mutable)List<OneTimeWorkRequest!> |
One or more |
| Returns | |
|---|---|
WorkContinuation |
A |
then
fun then(work: OneTimeWorkRequest): WorkContinuation
Adds new OneTimeWorkRequest items that depend on the successful completion of all previously added OneTimeWorkRequests.
| Parameters | |
|---|---|
work: OneTimeWorkRequest |
One or more |
| Returns | |
|---|---|
WorkContinuation |
A |