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, fromWebView:Boolean) -> Boolean)?,
    val start: suspend (action:String?) -> Unit,
    val resetToRoot:()->Unit
) {

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy