Sebastian Kürten
01/07/2022, 8:36 AMmutableStateOf()
and a background thread for potentially longer running tasks that deliver data and alter state variables. Naturally, sometimes buttons etc. also write to such state variables. Now we're wondering about thread safety and what kind of synchronization mechanisms we might need. I realize the state handling and snapshots do a lot of heavy lifting for us, but it would be really nice to read some documentation about that. I find next to nothing on that topic in the compose docs: https://developer.android.com/jetpack/compose/documentation We have found Zach's series "Compose state explained" https://dev.to/zachklipp/series/12895 and the articles there are very insightful. Still I'm wondering if there might be other "official" resources such as docs or references on those topics that we might have missed?Sebastian Kürten
01/07/2022, 8:36 AMZach Klippenstein (he/him) [MOD]
01/07/2022, 5:43 PMZach Klippenstein (he/him) [MOD]
01/07/2022, 5:43 PMSebastian Kürten
01/07/2022, 6:06 PMAndy Himberger
01/09/2022, 7:33 PMjava.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied
at androidx.compose.runtime.snapshots.SnapshotKt.readError(Snapshot.kt:1527)
at androidx.compose.runtime.snapshots.SnapshotKt.current(Snapshot.kt:1770)
at androidx.compose.runtime.SnapshotMutableStateImpl.setValue(SnapshotState.kt:299)
at com.zzz.PlaygroundViewModelImpl$1.invokeSuspend(PlaygroundViewModel.kt:178)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
though I guess this happens because my ViewModel is created on first usage from compose (which seems like a common pattern when using viewModel() helper)