arrow-fx / arrow.fx / MVar

MVar

interface ~~MVar~~<F, A> Deprecated: The IO datatype and it’s related type classes will disappear in Arrow 0.13.0. All useful operations are offered directly over suspend functions by Arrow Fx Coroutines. https://arrow-kt.io/docs/fx/async/

It’s a mutable variable with context F, that is either empty or contains a value of type A. A pure concurrent queue of size 1.

MVar is appropriate for building synchronization primitives and performing simple inter-thread communications.

Functions

isEmpty Returns true if there are no elements. Otherwise false.abstract fun isEmpty(): Kind<F, Boolean>
isNotEmpty Returns true if there no elements. Otherwise false.abstract fun isNotEmpty(): Kind<F, Boolean>
put 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.abstract fun put(a: A): Kind<F, Unit>
read Reads the current value without emptying the MVar, assuming there is one, or otherwise it blocks until there is a value available.abstract fun read(): Kind<F, A>
take Empties the MVar if full, returning the value, or blocks otherwise until a value is available.abstract fun take(): Kind<F, A>
tryPut Fill the MVar if we can do it without blocking. Returns true if successfully put the value or false otherwise.abstract fun tryPut(a: A): Kind<F, Boolean>
tryTake Try to take the value of MVar, returns result as an Option.abstract fun tryTake(): Kind<F, Option<A>>

Companion Object Functions

cancelable fun <F, A> ~~cancelable~~(initial: A, CF: Concurrent<F>): Kind<F, MVar<F, A>>
cancellable Create a cancellable MVar that’s initialized to an initial value.fun <F, A> cancellable(initial: A, CF: Concurrent<F>): Kind<F, MVar<F, A>>
empty Create an cancellable empty MVar.fun <F, A> empty(CF: Concurrent<F>): Kind<F, MVar<F, A>>
factoryCancelable fun <F> ~~factoryCancelable~~(CF: Concurrent<F>): MVarFactory<F>
factoryCancellable Build a MVarFactory value for creating MVar types F without deciding the type of the MVar’s value.fun <F> factoryCancellable(CF: Concurrent<F>): MVarFactory<F>
factoryUncancelable fun <F> ~~factoryUncancelable~~(AS: Async<F>): MVarFactory<F>
factoryUncancellable Build a MVarFactory value for creating MVar types F without deciding the type of the MVar’s value.fun <F> factoryUncancellable(AS: Async<F>): MVarFactory<F>
invoke Create an uncancellable MVar that’s initialized to an initial value.operator fun <F, A> invoke(initial: A, CF: Concurrent<F>): Kind<F, MVar<F, A>>
uncancelableEmpty fun <F, A> ~~uncancelableEmpty~~(AS: Async<F>): Kind<F, MVar<F, A>>
uncancelableOf fun <F, A> ~~uncancelableOf~~(initial: A, AS: Async<F>): Kind<F, MVar<F, A>>
uncancellableEmpty Create an uncancellable empty MVar.fun <F, A> uncancellableEmpty(AS: Async<F>): Kind<F, MVar<F, A>>
uncancellableOf Create an uncancellable MVar that’s initialized to an initial value.fun <F, A> uncancellableOf(initial: A, AS: Async<F>): Kind<F, MVar<F, A>>

Do you like Arrow?

Arrow Org
<