common open fun <A> TMVar<A>.take(): A

Read the value from a TMVar and empty it.

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

suspend fun main() {
  val tmvar = TMVar.new(10)
  val result = atomically {
  println("Result $result")
  println("New value ${atomically { tmvar.tryTake() } }")

This retries if the TMVar is empty and leaves the TMVar empty if it succeeded.

See also


arrow.fx.stm.STM for a version that does not remove the value after reading.

Do you like Arrow?

Arrow Org