//arrow-fx-stm/arrow.fx.stm/STM/tryTake

tryTake

common open fun <A> TMVar<A>.tryTake(): A?

Same as TMVar.take except 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.tryTake()
  }
  //sampleEnd
  println("Result $result")
  println("New value ${atomically { tmvar.tryTake() } }")
}

Do you like Arrow?

Arrow Org
<