arrow-fx-stm / arrow.fx.stm / STM / tryRead
open fun <A>
TMVar
<A>.tryRead(): A?
Same as TMVar.read except that it returns null if the TMVar is empty and thus never retries.
import arrow.fx.stm.TMVar
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tmvar = TMVar.empty<Int>()
val result = atomically {
tmvar.tryRead()
}
//sampleEnd
println("Result $result")
}
See Also
open fun <A>
TQueue
<A>.tryRead(): A?
Same as TQueue.read except it returns null if the TQueue is empty.
import arrow.fx.stm.TQueue
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tq = TQueue.new<Int>()
val result = atomically {
tq.tryRead()
}
//sampleEnd
println("Result $result")
println("Items in queue ${atomically { tq.flush() }}")
}
This function never retries.
Do you like Arrow?
✖