Ruben Quadros
10/24/2022, 7:17 AMFlow<Int>
In this function I have an api call which also returns a flow
What is the best way to give result back to the caller?
Sample code in threadRuben Quadros
10/24/2022, 7:20 AMfun apiCall(): Flow<Int> = flow {
delay(2000) // some network call
emit(3)
}
fun myFunc(): Flow<Int> = flow {
emit(1) //denote loading
apiCall()
//is the only way collecting here and emitting again?
// apiCall().collect { emit(it) }
}
call site
myFunc().collect {
//do something with each result
}
Joffrey
10/24/2022, 7:29 AMapiCall
return a flow of one element? One-shot calls are way easier to manipulate as simple suspend functionsJoffrey
10/24/2022, 7:31 AMemitAll
I guess, but I would really reconsider the apiCall
function firstRuben Quadros
10/24/2022, 7:32 AM