StmGauge

STM-based gauge that tracks a current value with min/max bounds.

Automatically tracks the minimum and maximum values ever set, useful for monitoring metrics like concurrent request counts.

Basic usage:

val gauge = StmGauge.create(0.0)
atomically { with(gauge) { set(42.0) } }
println(gauge.value()) // 42.0

Tracking min/max:

val gauge = StmGauge.create(0.0)
atomically { with(gauge) { set(10.0) } }
atomically { with(gauge) { set(5.0) } }
atomically { with(gauge) { set(8.0) } }

atomically {
with(gauge) {
println("Min: ${min()}") // 0.0
println("Max: ${max()}") // 10.0
println("Current: ${current()}") // 8.0
}
}

Types

Link copied to clipboard
object Companion

Factory for StmGauge.

Functions

Link copied to clipboard
fun STM.current(): Double

Reads the current gauge value within an STM transaction.

Link copied to clipboard
fun STM.max(): Double

Reads the maximum value ever recorded within an STM transaction.

Link copied to clipboard
fun STM.min(): Double

Reads the minimum value ever recorded within an STM transaction.

Link copied to clipboard
fun STM.set(value: Double)

Sets the gauge to value within an STM transaction. Automatically updates min/max tracking.

Link copied to clipboard
suspend fun value(): Double

Reads the current gauge value by running an atomic transaction.