value
Read the value from a TVar.
import arrow.fx.stm.TVar
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tvar = TVar.new(10)
val result = atomically {
tvar.value
}
//sampleEnd
println(result)
}
Content copied to clipboard
This comes with a few guarantees:
Any given TVar is only ever read once during a transaction.
When committing the transaction the value read has to be equal to the current value otherwise the transaction will retry