Skip to content

Instantly share code, notes, and snippets.

@takahirom
Created October 17, 2021 07:58
Show Gist options
  • Save takahirom/b1ed21c95d6f51bf530412354ab7d57e to your computer and use it in GitHub Desktop.
Save takahirom/b1ed21c95d6f51bf530412354ab7d57e to your computer and use it in GitHub Desktop.
val snapshot = Snapshot.takeMutableSnapshot()
thread {
viewModel.state.value = "changes from other thread"
}
snapshot.enter {
Thread.sleep(100)
println("in snapshot before change:" + viewModel.state)
viewModel.state.value = "change in snapshot"
println("in snapshot after change:" + viewModel.state)
}
snapshot.apply()
println("after apply:" + viewModel.state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment