I have only one flow, but the values I would like to emit are of different type, e.g.
fun someFunction(): Flow<Pair<Int, SomeStateType>> = flow {
emit(SomeStateType.LOADING)
repeat(100) { i ->
emit(i)
}
emit(SomeStateType.COMPLETE)
}
or
val intValue: MutableStateFlow<Int> // has to be a Channel
val valueState: MutableStateFlow<SomeStateType>
fun someFunction(): Unit {
valueState.value = SomeStateType.LOADING
repeat(100) { i ->
intValue.value = i
}
}
ok while writing this sample I noticed two things:
1.
in the latter case I would have to define a hot
Channel
to ensure my int values are not conflated.
2. I could let the caller decide when operation is done and introduce SomeStateType there. Then I just need
fun someFunction(): Flow<Int>
Sometimes just writing about the problem helps to make it more clear .