tryRead
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")
}
Content copied to clipboard
See also
for a function that leaves the TMVar empty after reading.
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() }}")
}
Content copied to clipboard
This function never retries.