Hi. I have some problem with `Channel`. Where is m...
# coroutines
g
Hi. I have some problem with
Channel
. Where is my error?
g
coroutineScope is never return, because child coroutine never finished (no one consumed value from
produce
, so channel never closed)
Also I'm not sure what are trying to do in listenChanged, the code in produce tries to consume own channel values. Maybe you need
this@WrapperDb.channel
General problem, that you cannot just hide coroutine scope like in you function listenTable1, as I said coroutineScope function has different semantics, it waits for all child coroutines to finish before return, so it's just not suitable for produce/actor, because never return until someone consume all the values from a channel so coroutine will finish. Instead, expose coroutine scope, make listenTable1 extension of CoroutineScope (or pase it as param of this function, but this is against style of all other builders), this will allow to start new coroutine and consume channel values
g
Yes, this#WrapperDb.channel
g
If you already have broadcast channel with changes, why not implement listenChanged like this:
Copy code
fun listenChanged(table: String) = channel.openSubscription().filter { it.tableName == table }
g
@gildor Thanks.
filter
work very good. It’s solve my problem
👍 1