write
Set the value of 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.write(20)
}
//sampleEnd
println(result)
}
Content copied to clipboard
Similarly to read this comes with a few guarantees:
For multiple writes to the same TVar in a transaction only the last will actually be performed
When committing the value inside the TVar, at the time of calling write, has to be the same as the current value otherwise the transaction will retry
Append an element to the TQueue.
import arrow.fx.stm.TQueue
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tq = TQueue.new<Int>()
atomically {
tq.write(2)
}
//sampleEnd
println("Items in queue ${atomically { tq.flush() }}")
}
Content copied to clipboard
This function never retries.