isEmpty
Check if a TMVar is empty. This function 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.isEmpty()
}
//sampleEnd
println("Result $result")
}
Content copied to clipboard
Because the state of a transaction is constant there can never be a race condition between checking if a
TMVar
is empty and subsequent reads in the same transaction.
Check if a 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.isEmpty()
}
//sampleEnd
println("Result $result")
}
Content copied to clipboard
This function never retries.
This function has to access both TVar's and thus may lead to increased contention, use sparingly.