I'm using the Preference APIs that return flows.
There are cases when I need to combine values from different preferences. I know I can use
flow.combine.
Since the method where I need to combine is a suspend function and the value from the flows do not need to flow anywhere anymore, I could also define something like this:
suspend fun <T> Flow<T>.currentValue(): T {
var res: T? = null
this.collect {
res = it
}
return res!!
}
and then just read one value at at time:
val val1 = flow1.currentValue()
val val2 = flow2.currentValue()
val val3 = flow3.currentValue()
Is there a better way to do it? Or should I just use the combine method?