runningWorker

Ensures a LifecycleWorker is running. Since worker can't emit anything, it can't trigger any WorkflowActions.

You may want to consider using SessionWorkflow. See note on LifecycleWorker and the docs for SessionWorkflow.

Parameters

key

An optional string key that is used to distinguish between identical Workers.


inline fun <T, W : Worker<T>, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.runningWorker(worker: W, key: String = "", noinline handler: (T) -> WorkflowAction<PropsT, StateT, OutputT>)(source)

Ensures worker is running. When the Worker emits an output, handler is called to determine the WorkflowAction to take. When the worker finishes, nothing happens (although another render pass may be triggered).

Like workflows, workers are kept alive across multiple render passes if they're the same type, and different workers of distinct types can be run concurrently. However, unlike workflows, workers are compared by their declared type, not their actual type. This means that if you pass a worker stored in a variable to this function, the type that will be used to compare the worker will be the type of the variable, not the type of the object the variable refers to.

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

Parameters

key

An optional string key that is used to distinguish between identical Workers.