any way to get rid of annoying channel cancellatio...
# coroutines
a
any way to get rid of annoying channel cancellation exception i have rather simple code on VM that look like
Copy code
suspend fun get() = stateChannelFlow(viewModelScope){firebase.database./**some stuff*/.get.addOnSuccessListener { data ->
       viewModelScope.launch {
            send(data)
       }
   }
}
ik, you could say you should have used stateFlow instead ofstateChannelFlow I did but it forced me to use channel over regular flow btw called this function in Fragment() lifecycleScope at this time i have no idea if I messed the coroutine thing on get() but i tried my best trying d/n things which failed N: this is the code for the extension function
Copy code
suspend fun <T>stateChannelFlow(scope: CoroutineScope, @BuilderInference block: suspend ProducerScope<T>.() -> Unit): StateFlow<T> = channelFlow(block).stateIn(scope)
g
What are you trying to achieve here? I don’t see why you need channels in this case at all I’mn not sure how firebase API works here, but fir one time request you should instead write (or use existing) suspend function adapter, and for stream data see how existing adapters implemented and callbackFlow builder
Also there it’s not a good style to have a suspend function which returns Flow
If you share what kind types you want to use and how they work, I can help with adapter I actually surprised that there is no official firebase database adapter for coroutines
s
g
a
Thanks,it was quiet frustrating but with a bit of research I found out I need to use firestore's await that allows me to get rid of channel flow and use
stateFlow
which was quite nice However it wasn't working as I wanted it I was expecting it to update the UI with stream of data change
Btw sorry for not mentioning the database i used it was firestore not FB R-T DB
g
I was expecting it to update the UI with stream of data change
Maybe they have flow adapter? If they don’t you can write own with callbackFlow