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

commonMain.org.kodein.di.internal.concurrent.kt Maven / Gradle / Ivy

There is a newer version: 7.23.1
Show newest version
package org.kodein.di.internal

public expect inline fun  maySynchronized(lock: Any?, block: () -> R): R

/** @suppress */
public inline fun  synchronizedIfNull(lock: Any?, predicate: () -> T?, ifNotNull: (T) -> R, ifNull: () -> R): R {
    predicate()?.let {
        return ifNotNull(it)
    }

    val value = maySynchronized(lock) {
        predicate()?.let { return@maySynchronized it }

        return ifNull()
    }

    return ifNotNull(value)
}

/** @suppress */
internal inline fun  synchronizedIfNotNull(lock: Any?, predicate: () -> T?, ifNull: () -> R, ifNotNull: (T) -> R): R {
    if (predicate() == null) {
        return ifNull()
    }

    maySynchronized(lock) {
        val value = predicate() ?: return@maySynchronized

        return ifNotNull(value)
    }

    return ifNull()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy