https://kotlinlang.org logo
Title
g

goldin

12/25/2018, 9:43 PM
Hi. I have some problem with
Channel
. Where is my error?
g

gildor

12/26/2018, 12:29 AM
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

goldin

12/26/2018, 1:48 AM
Yes, this#WrapperDb.channel
g

gildor

12/26/2018, 1:55 AM
If you already have broadcast channel with changes, why not implement listenChanged like this:
fun listenChanged(table: String) = channel.openSubscription().filter { it.tableName == table }
g

goldin

12/26/2018, 9:45 AM
@gildor Thanks.
filter
work very good. It’s solve my problem
👍 1