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

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

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

import com.lightningkite.lightningserver.engine.engine
import kotlinx.coroutines.CoroutineScope
import kotlinx.serialization.KSerializer

data class Task(
    val name: String,
    val serializer: KSerializer,
    val implementation: suspend CoroutineScope.(INPUT) -> Unit
) {
    init {
        Tasks.tasks[name] = this
    }

    @Suppress("UNCHECKED_CAST")
    suspend operator fun invoke(input: INPUT) = engine.launchTask(this as Task, input)

    override fun toString(): String {
        return "TASK $name"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy