Stm Counter
STM-based counter that can be atomically incremented/decremented.
Uses Arrow's Software Transactional Memory to provide lock-free, composable atomic operations on a counter value.
Basic usage:
val counter = StmCounter.create(0L)
atomically { with(counter) { increment() } }
println(counter.value()) // 1Content copied to clipboard
Composing with other STM operations:
val counter = StmCounter.create(0L)
val gauge = StmGauge.create(0.0)
atomically {
val count = with(counter) { increment() }
with(gauge) { set(count.toDouble()) }
}Content copied to clipboard
Batch updates inside a single transaction:
atomically {
with(counter) {
add(10)
decrement()
}
}
println(counter.value()) // 9Content copied to clipboard
Types
Link copied to clipboard
object Companion
Factory for StmCounter.