RxWorker
abstract class RxWorker : ListenableWorker
kotlin.Any | ||
↳ | androidx.work.ListenableWorker | |
↳ | androidx.work.rxjava3.RxWorker |
RxJava3 interoperability Worker implementation.
When invoked by the WorkManager
, it will call @createWork()
to get a Single<Result>
subscribe to it.
By default, RxWorker will subscribe on the thread pool that runs WorkManager
Worker
s. You can change this behavior by overriding getBackgroundScheduler()
method.
An RxWorker is given a maximum of ten minutes to finish its execution and return a androidx.work.ListenableWorker.Result
. After this time has expired, the worker will be signalled to stop.
Summary
Public constructors | |
---|---|
<init>(@NonNull appContext: Context, @NonNull workerParams: WorkerParameters) |
Public methods | |
---|---|
abstract Single<ListenableWorker.Result!> |
Override this method to define your actual work and return a |
open Unit | |
Completable |
setCompletableProgress(@NonNull data: Data) Updates the progress for a |
ListenableFuture<ListenableWorker.Result!> |
Protected methods | |
---|---|
open Scheduler |
Returns the default background scheduler that |
Inherited functions | |
---|---|
Public constructors
<init>
RxWorker(
@NonNull appContext: Context,
@NonNull workerParams: WorkerParameters)
Parameters | |
---|---|
appContext |
Context: The application Context |
workerParams |
WorkerParameters: Parameters to setup the internal state of this worker |
Public methods
createWork
@MainThread @NonNull abstract fun createWork(): Single<ListenableWorker.Result!>
Override this method to define your actual work and return a Single
of androidx.work.ListenableWorker.Result
which will be subscribed by the WorkManager
.
If the returned Single
fails, the worker will be considered as failed.
If the RxWorker
is cancelled by the WorkManager
(e.g. due to a constraint change), WorkManager
will dispose the subscription immediately.
By default, subscription happens on the shared Worker
pool. You can change it by overriding getBackgroundScheduler()
.
An RxWorker is given a maximum of ten minutes to finish its execution and return a androidx.work.ListenableWorker.Result
. After this time has expired, the worker will be signalled to stop.
Return | |
---|---|
Single<ListenableWorker.Result!> |
a Single<Result> that represents the work. |
onStopped
@CallSuper open fun onStopped(): Unit
setCompletableProgress
@NonNull fun setCompletableProgress(@NonNull data: Data): Completable
Updates the progress for a RxWorker
. This method returns a Completable
similar to the ListenableWorker#setProgressAsync(Data)
API.
Parameters | |
---|---|
data |
Data: The progress Data |
Return | |
---|---|
Completable |
The Completable |
startWork
@NonNull fun startWork(): ListenableFuture<ListenableWorker.Result!>
Protected methods
getBackgroundScheduler
@NonNull protected open fun getBackgroundScheduler(): Scheduler
Returns the default background scheduler that RxWorker
will use to subscribe.
The default implementation returns a Scheduler that uses the Executor
which was provided in WorkManager
's Configuration
(or the default one it creates).
You can override this method to change the Scheduler used by RxWorker to start its subscription. It always observes the result of the Single
in WorkManager's internal thread.
Return | |
---|---|
Scheduler |
The default Scheduler . |