isEmpty

open fun <A> TMVar<A>.isEmpty(): Boolean

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")
}

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.


open fun <A> TQueue<A>.isEmpty(): Boolean

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")
}

This function never retries.

This function has to access both TVar's and thus may lead to increased contention, use sparingly.