https://kotlinlang.org logo
Title
h

halirutan

01/13/2022, 1:44 AM
I have a data/state question. In my business layer I fetch data-points from a webservice and synchronize a local db. I have a listener API where I can execute code every time a new datapoint is ready. All this happens in the
<http://Dispatchers.IO|Dispatchers.IO>
coroutine scope. Now, since I'm a compose noob, I have a mutable state list, where I append the datapoints. I rarely get a
ConcurrentModificationException
exception which I guess is because the list is modified in the IO scope and read in the UI by compose. I read that one solution is to basically use a mutable state of an immutable list and assign a new list. That sounds a lot like I don't want to do this. Isn't there a better way to have a long list of datapoints that I can update from the IO thread?
And please don't refrain from telling me I'm a moron! I'm here for the fun and use every chance to learn. The tips I got from here already helped a lot and I could implement a live crypto chart that works amazingly fast even with 10k datapoints
k

Kirill Grouchnikov

01/13/2022, 2:14 AM
This is a general #compose question, looks like
h

halirutan

01/13/2022, 2:25 AM
@Kirill Grouchnikov I thought because Jetpack compose has
ViewModel
the answer might not be applicable for desktop. That's why I asked here.
m

Michael Paus

01/13/2022, 10:58 AM
I think that problem can be solved by just using a persistent list from here: https://github.com/Kotlin/kotlinx.collections.immutable
m

mcpiroman

01/13/2022, 11:29 AM
Also note `mutableStateListOf()`is mostly a wrapper for
persistentListOf()
from the library above
:kotlin-intensifies: 1
h

halirutan

01/13/2022, 2:59 PM
Alright, thanks a lot. Let me look into this.