isNotEmpty

open fun <A> TMVar<A>.isNotEmpty(): Boolean(source)

Check if a TMVar is not 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.isNotEmpty()
}
//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>.isNotEmpty(): Boolean(source)

Check if a TQueue is not empty.

import arrow.fx.stm.TQueue
import arrow.fx.stm.atomically

suspend fun main() {
//sampleStart
val tq = TQueue.new<Int>()
val result = atomically {
tq.isNotEmpty()
}
//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.