derivedWhileSubscribed
fun <T> derivedWhileSubscribed(initial: T, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = null, observer: CoAutoRunCallback<T>): StateFlow<T>
Creates a StateFlow that computes its value based on other StateFlows via a suspendable coAutoRun block.
This doesn't need a CoroutineScope/CoroutineLauncher and has SharingStarted.WhileSubscribed behavior. If you have access to a CoroutineScope/CoroutineLauncher you should better use the normal derived functions.
Parameters
initial
The initial value (until the first computation finishes).
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 null
.
observer
The callback which is used to track the observables.