arrow-fx-coroutines / arrow.fx.coroutines / ConcurrentVar / read
abstract suspend fun read(): A
Reads the current value without emptying the ConcurrentVar, assuming there is one, or otherwise it suspends until there is a value available.
import arrow.fx.coroutines.*
suspend fun main(): Unit {
//sampleStart
val mvar = ConcurrentVar.empty<Int>()
val none = timeOutOrNull(1.seconds) {
mvar.read()
}
mvar.put(10)
val read1 = mvar.read()
val read2 =mvar.read()
//sampleEnd
println("none: $none, read1: $read1, read2: $read2")
}
Do you like Arrow?
✖