All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmCommonMain.com.badoo.reaktive.utils.lock.ConditionLock.kt Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package com.badoo.reaktive.utils.lock

import com.badoo.reaktive.utils.InternalReaktiveApi
import java.util.concurrent.locks.ReentrantLock
import kotlin.time.Duration
import kotlin.time.Duration.Companion.nanoseconds

@InternalReaktiveApi
actual open class ConditionLock : ReentrantLock() {

    private val condition = super.newCondition()

    actual fun await(timeout: Duration): Duration =
        if (timeout.isInfinite()) {
            condition.await()
            Duration.INFINITE
        } else {
            condition
                .awaitNanos(timeout.coerceAtLeast(Duration.ZERO).inWholeNanoseconds)
                .nanoseconds
        }

    actual fun signal() {
        condition.signalAll()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy