Add name to InMemory services
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
package eventDemo.libs.bus
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.github.oshai.kotlinlogging.withLoggingContext
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class BusInMemory<E> : Bus<E> {
|
||||
class BusInMemory<E>(
|
||||
val name: KClass<*> = BusInMemory::class,
|
||||
) : Bus<E> {
|
||||
private val logger = KotlinLogging.logger(name.qualifiedName.toString())
|
||||
private val subscribers: MutableList<Pair<Int, suspend (E) -> Unit>> = mutableListOf()
|
||||
|
||||
override suspend fun publish(item: E) {
|
||||
withLoggingContext("busItem" to item.toString()) {
|
||||
logger.info { "Item sent to the bus: $item" }
|
||||
subscribers
|
||||
.sortedByDescending { (priority, _) -> priority }
|
||||
.forEach { (_, block) ->
|
||||
|
||||
Reference in New Issue
Block a user