commonMain.dev.mokkery.internal.Counter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mokkery-runtime Show documentation
Show all versions of mokkery-runtime Show documentation
Mokkery is a mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven.
The newest version!
package dev.mokkery.internal
import kotlinx.atomicfu.atomic
internal fun interface Counter {
fun next(): Long
companion object {
private val _callsClock = MonotonicCounter(Long.MIN_VALUE)
private val _mocksCounter = MonotonicCounter(1)
val calls: Counter = _callsClock
val mocks: Counter = _mocksCounter
}
}
internal class MonotonicCounter(start: Long): Counter {
private val current = atomic(start)
override fun next(): Long = current.getAndIncrement()
}