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

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

for a version that does not retry.

for a version that does not remove the value after reading.