//arrow-fx-stm/arrow.fx.stm/STM/isNotEmpty

isNotEmpty

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

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.


common open fun <A> TQueue<A>.isNotEmpty(): Boolean

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](../-t-var/index.html)'s and thus may lead to increased contention, use sparingly.


Do you like Arrow?

Arrow Org
<