com.lightningkite.lightningserver.tasks.Task.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server-core Show documentation
Show all versions of server-core Show documentation
A set of tools to fill in/replace what Ktor is lacking in.
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"
}
}