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

r4zzz4k

12/15/2017, 1:39 PM
Do I understand correctly that there are no ways to have observable collection out of the box? So if I want observable list, I have to have either a channel holding either new copy of the list or incremental changes depending on the use-case?
e

elizarov

12/15/2017, 2:00 PM
I would not recommend combining observability and concurrency. Observable frameworks better be confined to UI thread.
r

r4zzz4k

12/15/2017, 2:21 PM
I'm actually not having UI in mind, I'm thinking about decoupling of business logic from input events. Right now I have a chain of producers which gets byte buffer from some place (static test data, will later be provided by hardware I/O, doesn't matter for the question though), parses them into well-known commands (described as sealed class) and then updates data layer consisting of several classes with `BroadcastChannel`s. Now I'm working on the logic itself which should act on these classes, and that's where the question regarding collection arises -- there is a collection of entities which can change over the lifetime, and I want to react to these changes. Thinking about it a bit more -- every entity has unique tag, so it's probably just a matter of an additional sealed class with
Added(tag, value)
,
Removed(tag)
and changes to the entities themselves should be covered by their own channels. Or am I missing something?
Sorry for quite cumbersome description, I still don't have bird's-eye view on what I'm implementing in mind.
e

elizarov

12/15/2017, 3:20 PM
We don't have an out-of-the-box abstraction readily available, but there was somewhat similar use-case that is recorded here: https://github.com/Kotlin/kotlinx.coroutines/issues/145
r

r4zzz4k

12/15/2017, 4:17 PM
Yes, looks similar to what I'm looking for, probably with an added notification when new entity is added or removed. Thank you for the link. I should probably investigate if similar problem is solved in some actor framework or coroutine / channel implementation.
2 Views