Created
October 17, 2021 07:54
-
-
Save takahirom/9c63a2f4a900a700720a3ba163c05428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewModel { | |
val state = mutableStateOf("init") | |
} | |
fun main() { | |
val viewModel = ViewModel() | |
viewModel.state.value = "before snapshot" | |
val snapshot = Snapshot.takeMutableSnapshot() | |
// Changes from other threads | |
thread { // Start another thread | |
viewModel.state.value = "changes from other thread" | |
} | |
snapshot.enter { | |
// wait changes from other threads | |
Thread.sleep(100) | |
println("in snapshot:" + viewModel.state) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment