Flow: Lifecycle operators - devrath/KotlinAlchemy GitHub Wiki
What are lifecycle operators
These are the operators that are triggered only once during the lifecycle of a flow
Some lifecycle operators
onStart
-------> Triggered during the start of the flowonCompletion
--> Triggered during the completion of flow
Code
viewModelScope.launch {
data.getData(context)
.map { dataList ->
}.onStart {
// We indicate the UI will start loading
}.catch { error ->
// Emit the error if the error is found
}.onCompletion {
// This indicates flow is completed
}.collect()
}