arrow-fx-coroutines / arrow.fx.coroutines / ConcurrentVar / take

take

abstract suspend fun take(): A

Empties the ConcurrentVar if full, returning the value, or suspend until a value is available.

import arrow.fx.coroutines.*

suspend fun main(): Unit {
//sampleStart
val mvar = ConcurrentVar(5)
val five = mvar.take()
val none = timeOutOrNull(1.seconds) {
  mvar.take()
}
//sampleEnd
println("five: $five, none: $none")
}

Do you like Arrow?

Arrow Org
<