SimpleCoroutineLauncher

open class SimpleCoroutineLauncher(val scope: CoroutineScope) : CoroutineLauncher

Simple default implementation of a CoroutineLauncher which uses a given CoroutineScope.

Usually you'll want to use a ReactiveViewModel or maybe BaseReactiveState.

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope)

Properties

Link copied to clipboard
override val loading: MutableStateFlow<Int>

The default loading tracker.

Link copied to clipboard
override val scope: CoroutineScope

The underlying CoroutineScope of this launcher.

Functions

Link copied to clipboard

Watches observables for changes. Often useful to keep things in sync (e.g. CoroutineLauncher -> UI).

Link copied to clipboard
fun CoroutineLauncher.coAutoRun(onChange: CoAutoRunOnChangeCallback<Unit>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = loading, observer: CoAutoRunCallback<Unit>): CoAutoRunner<Unit>

Watches observables for changes. Often useful to keep things in sync (e.g. CoroutineLauncher -> UI).

Link copied to clipboard
fun <T> CoroutineLauncher.derived(synchronous: Boolean = true, cache: Boolean = synchronous, observer: AutoRunCallback<T>): StateFlow<T>

Creates a StateFlow that computes its value based on other StateFlows via an autoRun block.

fun <T> CoroutineLauncher.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = loading, observer: CoAutoRunCallback<T>): StateFlow<T>

Creates a StateFlow that computes its value based on other StateFlows via a suspendable coAutoRun block.

Link copied to clipboard
fun CoroutineLauncher.invokeOnCompletion(handler: CompletionHandler): Disposable

Helper for adding a completion handler to a CoroutineLauncher.

Link copied to clipboard
open fun launch(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, withLoading: MutableStateFlow<Int>? = loading, onError: suspend (Throwable) -> Unit? = null, block: suspend CoroutineScope.() -> Unit): Job

Launches a coroutine. Mark long-running coroutines by setting withLoading to loading state.

Link copied to clipboard
open fun onError(error: Throwable)
Link copied to clipboard
open fun rawLaunch(context: CoroutineContext, start: CoroutineStart, block: suspend CoroutineScope.() -> Unit): Job

Launches a coroutine without any error handling or loading state tracking.

Link copied to clipboard
open suspend fun track(withLoading: MutableStateFlow<Int>? = loading, onError: suspend (Throwable) -> Unit? = null, block: suspend () -> Unit)

Tracks a suspension block's loading state and errors.

Link copied to clipboard