What is the best way to obtain the last element emitted by a flow without receiving updates.
Question: I use a flow to observe changes in certain shared preferences, but sometimes I want to know the current value of that preference. I always use two functions, one to observe the values in a flow and the other to capture the data directly, is there any way to archive the same behavior with just the observer function?
suspend fun getBreadcrumb(): Breadcrumb =
withContext(Dispatchers.IO) context@ {
...
}
fun observeBreadcrumb(): Flow<Breadcrumb> {
....
}
collect
actually stop the flow emitting? – Retroversion