arrow-fx-stm / arrow.fx.stm / STM / tryPut
open fun <A> TMVar<A>.tryPut(a: A): Boolean
Same as TMVar.put except that it returns true or false if was successful or it retried.
import arrow.fx.stm.TMVar
import arrow.fx.stm.atomically
suspend fun main() {
  //sampleStart
  val tmvar = TMVar.new(20)
  val result = atomically {
    tmvar.tryPut(30)
  }
  //sampleEnd
  println("Result $result")
  println("New value ${atomically { tmvar.tryTake() } }")
}
This function never retries.
See Also
Do you like Arrow?
✖