Package arrow.fx.stm


Name Summary
STM common interface STM
Consistent and safe concurrent state updates
Software transactional memory, or STM, is an abstraction for concurrent state modification.
TArray common data class TArray<A>
A TArray is an array of transactional variables.
TMap common data class TMap<K, V>
A TMap is a concurrent transactional implementation of a key value hashmap.
TMVar common data class TMVar<A>
A TMVar is a mutable reference that can either be empty or hold a value.
TQueue common data class TQueue<A>
A TQueue is a transactional unbounded queue which can be written to and read from concurrently.
TSemaphore common data class TSemaphore
TSemaphore is the transactional Semaphore.
TSet common data class TSet<A>
A TSet is a concurrent transactional implementation of a hashset.
TVar common class TVar<A>
A TVar is a mutable reference that can only be (safely) accessed inside a STM transaction.


Name Summary
atomically common suspend fun <A> atomically(f: STM.() -> A): A
Run a transaction to completion.
check common fun STM.check(b: Boolean)
Retry if b is false otherwise does nothing.
newEmptyTMVar common fun <A> STM.newEmptyTMVar(): TMVar<A>
newTArray common fun <A> STM.newTArray(vararg arr: A): TArray<A>
fun <A> STM.newTArray(xs: Iterable<A>): TArray<A>
fun <A> STM.newTArray(size: Int, a: A): TArray<A>
fun <A> STM.newTArray(size: Int, f: (Int) -> A): TArray<A>
newTMap common fun <K, V> STM.newTMap(): TMap<K, V>
fun <K, V> STM.newTMap(fn: (K) -> Int): TMap<K, V>
newTMVar common fun <A> STM.newTMVar(a: A): TMVar<A>
newTQueue common fun <A> STM.newTQueue(): TQueue<A>
newTSem common fun STM.newTSem(initial: Int): TSemaphore
newTSet common fun <A> STM.newTSet(): TSet<A>
fun <A> STM.newTSet(fn: (A) -> Int): TSet<A>
stm common inline fun <A> stm(noinline f: STM.() -> A): STM.() -> A
Helper to create stm blocks that can be run with STM.orElsekotlin:ank:playground import arrow.fx.stm.atomically import arrow.fx.stm.stm<br>suspend fun main() { //sampleStart val i = 4 val result = atomically { stm { if (i == 4) retry() "Not 4" } orElse { "4" } } //sampleEnd println("Result $result") }Equal to suspend just with an STM receiver.

Do you like Arrow?

Arrow Org