Skip to content

Instantly share code, notes, and snippets.

@takahirom
Created October 17, 2021 07:54
Show Gist options
  • Save takahirom/9c63a2f4a900a700720a3ba163c05428 to your computer and use it in GitHub Desktop.
Save takahirom/9c63a2f4a900a700720a3ba163c05428 to your computer and use it in GitHub Desktop.
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