//reactivestate-core/com.ensody.reactivestate/CoAutoRunner
CoAutoRunner¶
class CoAutoRunner<T>(val launcher: CoroutineLauncher, onChange: CoAutoRunOnChangeCallback<T>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = launcher.loading, immediate: Boolean = false, observer: CoAutoRunCallback<T>) : InternalBaseAutoRunner
Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI). This is the suspension function based version. See AutoRunner for the synchronous version.
Given an observer, this class will automatically register itself as a listener and keep track of the observables which observer depends on.
You have to call run once to start watching.
To stop watching, you should call dispose.
Instead of instantiating an AutoRunner
directly you’ll usually want to use an autoRun helper.
Parameters¶
common
launcher | The CoroutineLauncher to use. |
onChange | Gets called when the observables change. Your onChange handler has to manually call run at any point (e.g. asynchronously) to change the tracked observables. |
flowTransformer | How changes should be executed/collected. Defaults to conflatedWorker. |
dispatcher | The CoroutineDispatcher to use. Defaults to dispatchers.main . |
withLoading | Tracks loading state for the (re-)computation. Defaults to CoroutineLauncher.loading. |
immediate | Whether to start tracking in a background coroutine immediately. |
observer | The callback which is used to track the observables. |
Constructors¶
CoAutoRunner | [common] constructor(launcher: CoroutineLauncher, onChange: CoAutoRunOnChangeCallback<T>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = launcher.loading, immediate: Boolean = false, observer: CoAutoRunCallback<T>) |
Properties¶
Name | Summary |
---|---|
attachedDisposables | [common] open override val attachedDisposables: DisposableGroup The attached disposables which should be auto-disposed when this object is disposed. |
launcher | [common] override val launcher: CoroutineLauncher |
Functions¶
Name | Summary |
---|---|
dispose | [common] open override fun dispose() Stops watching observables. |
disposeOnCompletionOf | [common] fun Disposable.disposeOnCompletionOf(launcher: CoroutineLauncher): Disposable Disposes the Disposable when CoroutineLauncher completes (including cancellation). [common] fun Disposable.disposeOnCompletionOf(context: CoroutineContext): Disposable Disposes the Disposable when CoroutineContext completes (including cancellation). [common] fun Disposable.disposeOnCompletionOf(scope: CoroutineScope): Disposable Disposes the Disposable when CoroutineScope completes (including cancellation). [common] fun Disposable.disposeOnCompletionOf(job: Job): Disposable Disposes the Disposable when Job completes (including cancellation). |
run | [common] suspend fun run(once: Boolean = false): T Calls observer and tracks its dependencies unless once is true . |
triggerChange | [common] open override fun triggerChange() |