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

commonMain.ru.alexey.event.threads.LocalScopeHolder.kt Maven / Gradle / Ivy

package ru.alexey.event.threads

import androidx.compose.runtime.staticCompositionLocalOf
import ru.alexey.event.threads.scopeholder.ScopeHolder
import kotlin.jvm.JvmInline

val LocalScopeHolder = staticCompositionLocalOf { error("Scope holder not provided!") }
val LocalScope = staticCompositionLocalOf { error("Scope not provided!") }

@JvmInline
value class ScopeCounter(
    private val counts: MutableMap
) {
    fun register(name: String) {
        counts[name] = counts.getOrElse(name) { 0 } + 1
    }
    fun unregister(name: String): Boolean {
        val next = counts.getOrElse(name) { 1 } - 1
        return if (next == 0) {
            counts.remove(name)
            true
        } else {
            counts[name] = next
            false
        }
    }
}

internal val LocalScopeCounter = staticCompositionLocalOf { error("Init ScopeHolder first!") }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy