//arrow-fx-stm/arrow.fx.stm/STM/take
common open fun <A> TMVar<A>.take(): A
Read the value from a TMVar and empty it.
import arrow.fx.stm.TMVar
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tmvar = TMVar.new(10)
val result = atomically {
tmvar.take()
}
//sampleEnd
println("Result $result")
println("New value ${atomically { tmvar.tryTake() } }")
}
This retries if the TMVar is empty and leaves the TMVar empty if it succeeded.
common
arrow.fx.stm.STM | for a version that does not remove the value after reading. |
Do you like Arrow?
✖