Return a [SnapshotContextElement] that will [enter][Snapshot.
snapshotAsContextElementSample
@Suppress("unused")
fun snapshotAsContextElementSample() {
runBlocking {
val snapshot = Snapshot.takeSnapshot()
try {
withContext(snapshot.asContextElement()) {
// Data observed by separately reading stateA and stateB are consistent with
// the snapshot context element across suspensions
doSomethingSuspending(someObject.stateA)
doSomethingSuspending(someObject.stateB)
}
} finally {
// Snapshot must be disposed after it will not be used again
snapshot.dispose()
}
}
}