I have a `LiveData<List<Match>>` objec...
# android
m
I have a
LiveData<List<Match>>
object in my ViewModel, and I observe the list in my view. The
Match
objects in the list come from a network source, one at a time. So I never set the entire list at once, but rather I add a single
Match
to the list when I receive it. This is my solution so far, when I receive a new
Match
object:
Copy code
val matches = liveMatches.value?.toMutableList() ?: mutableListOf()
matches.add(newMatch)
liveMatches.value = matches
It seems to work, but I am worried about simultaneous updates. Don’t I risk missing some objects because of a race condition with this approach?