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

com.lightningkite.lightningserver.tasks.Tasks.kt Maven / Gradle / Ivy

The newest version!
package com.lightningkite.lightningserver.tasks

object Tasks {
    val tasks = HashMap>()

    private val onSettingsReadyActions = HashSet()
    fun onSettingsReady(priority: Double = 0.0, action: suspend () -> Unit): StartupAction {
        if (isSettingsReady) throw IllegalStateException()
        val result = StartupAction(priority, action)
        onSettingsReadyActions.add(result)
        return result
    }

    var isSettingsReady = false
        private set

    suspend fun onSettingsReady() {
        if (isSettingsReady) return
        isSettingsReady = true
        onSettingsReadyActions.sortedByDescending { it.priority }.forEach { it.action() }
        onSettingsReadyActions.clear()
    }

    private val onEngineReadyActions = HashSet()
    fun onEngineReady(priority: Double = 0.0, action: suspend () -> Unit): StartupAction {
        if (isEngineReady) throw IllegalStateException()
        val result = StartupAction(priority, action)
        onEngineReadyActions.add(result)
        return result
    }

    var isEngineReady = false
        private set

    suspend fun onEngineReady() {
        if (isEngineReady) return
        isEngineReady = true
        onEngineReadyActions.sortedByDescending { it.priority }.forEach { it.action() }
        onEngineReadyActions.clear()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy