//arrow-fx-stm/arrow.fx.stm/STM/put

put

common open fun <A> TMVar<A>.put(a: A)

Put a value into an empty TMVar.

import arrow.fx.stm.TMVar
import arrow.fx.stm.atomically

suspend fun main() {
  //sampleStart
  val tmvar = TMVar.empty<Int>()
  atomically {
    tmvar.put(20)
  }
  //sampleEnd
  println("New value ${atomically { tmvar.tryTake() } }")
}

This retries if the TMVar is not empty.

For a version of TMVar.put that does not retry see TMVar.tryPut

Do you like Arrow?

Arrow Org
<