LifecycleWorker

abstract class LifecycleWorker : Worker<Nothing> (source)

Worker that performs some action when the worker is started and/or stopped.

A Worker is stopped when its parent Workflow finishes a render pass without running the worker, or when the parent workflow is itself torn down.

Note that there is currently an issue which can effect whether a LifecycleWorker is ever executed. See more details at BaseRenderContext.runningSideEffect.

Also note that LifecycleWorker is inherently racy with other Workers. There is no guarantee this will run first or last compared to other workers and side effects. Ideally setup and teardown is handled by each Worker or sideEffect itself. Consider using a try { } finally { } or Flow.onCompletion to handle that.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun doesSameWorkAs(otherWorker: Worker<*>): Boolean

Equates LifecycleWorkers that have the same concrete class.

Link copied to clipboard
open fun onStarted()

Called when this worker is started. It is executed concurrently with the parent workflow – the first render pass that starts this worker will not wait for this method to return, and one or more additional render passes may occur before this method is called. This behavior may change to be more strict in the future.

Link copied to clipboard
open fun onStopped()

Called when this worker has been torn down. It is executed concurrently with the parent workflow – the render pass that cancels (stops) this worker will not wait for this method to return, and one or more additional render passes may occur before this method is called. This behavior may change to be more strict in the future.

Link copied to clipboard
override fun run(): Flow<Nothing>

Returns a Flow to execute the work represented by this worker.

Link copied to clipboard
fun <T, R> Worker<T>.transform(transform: (Flow<T>) -> Flow<R>): Worker<R>

Returns a Worker that transforms this Worker's Flow by calling transform.