https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

Marko Mitic

05/21/2019, 11:28 AM
Hi everyone, I'm starting to use coroutines in prod and could use a bit of advice. I need to observe state of couple of components, both should offer subscribe/unsubscribe ops. I'm thinking of having a channel for each, created on subscription, canceling does the unsubscribe, and observe both using
select
. Is that fine? Are there any channel constructs that could help?
g

gildor

05/21/2019, 11:28 AM
Probably better to use Flow for this
but you also can use Channel
But if you need select for Channel, so probably you need something like combineLatest for Flow, but it’s not available yet in the latest version, but probably will be in upcoming. PR already opened https://github.com/Kotlin/kotlinx.coroutines/issues/1193
m

Marko Mitic

05/21/2019, 11:32 AM
what's the status of Flow, I'm writing a library here and I don't have full control of coroutine lib version, so I'm trying to use only stable APIs
g

gildor

05/21/2019, 11:33 AM
Channels are also Experimental, some operators marked as Obsolete
so I don’t think that situation is very different
I would just use Flow
m

Marko Mitic

05/21/2019, 11:34 AM
Isn't just subset of channel API experimental?
g

gildor

05/21/2019, 11:37 AM
Yes, subset
but this “subset” is actually all operators, many methods of Channel, whole BroadcastChannel API
you probably can avoid using them, but it will be not easy
4 Views