Clean and fix

This commit is contained in:
2025-03-05 22:11:24 +01:00
parent d84e8359c9
commit 99f0760d3c
11 changed files with 110 additions and 92 deletions

View File

@@ -1,5 +1,8 @@
package eventDemo.libs.command
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlin.reflect.KClass
/**
@@ -11,7 +14,7 @@ interface CommandStream<C : Command> {
/**
* Send a new [Command] to the queue.
*/
suspend fun send(
fun send(
type: KClass<C>,
command: C,
)
@@ -19,7 +22,7 @@ interface CommandStream<C : Command> {
/**
* Send multiple [Command] to the queue.
*/
suspend fun send(
fun send(
type: KClass<C>,
vararg commands: C,
) {
@@ -39,6 +42,13 @@ interface CommandStream<C : Command> {
* Apply an action to all command income in the stream.
*/
suspend fun process(action: CommandBlock<C>)
@OptIn(DelicateCoroutinesApi::class)
fun blockAndProcess(action: CommandBlock<C>) {
GlobalScope.launch {
process(action)
}
}
}
suspend inline fun <reified C : Command> CommandStream<C>.send(vararg command: C) = send(C::class, *command)