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() {
  val tmvar = TMVar.empty<Int>()
  atomically {
  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