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

commonMain.tech.skot.core.SKFeatureInitializer.kt Maven / Gradle / Ivy

There is a newer version: 1.2.9
Show newest version
package tech.skot.core

import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

abstract class SKFeatureInitializer(
    val initialize: suspend () -> Unit,
    val onDeepLink: ((uri: SKUri) -> Unit)?,
    val start: suspend () -> Unit,
) {

    private var done = false
    private val initializeMutex = Mutex()
    suspend fun initializeIfNeeded(uri: SKUri?) {
        if (!done && onDeepLink != null) {
            initializeMutex.withLock {
                if (!done) {
                    done = true
                    initialize()
                    uri?.let { onDeepLink.invoke(uri) }
                    start()
                }
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy