arrow-fx / arrow.fx / MVar / put
abstract fun put(a: A): Kind<F,
Unit
>
Puts A in the MVar if it is empty, or blocks if full until the given value is next in line to be consumed by take.
import arrow.fx.*
import arrow.fx.extensions.io.async.async
import arrow.fx.extensions.io.monad.flatMap
fun main(args: Array<String>) {
//sampleStart
val mvar = MVar.factoryUncancellable(IO.async())
mvar.empty<Int>().flatMap { v ->
v.put(5).flatMap {
v.take()
}
}.unsafeRunSync() == 5
//sampleEnd
}
Do you like Arrow?
✖