com.lightningkite.lightningserver.pubsub.LocalPubSub.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.pubsub
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
object LocalPubSub : PubSub {
val known = HashMap>()
@Suppress("UNCHECKED_CAST")
override fun get(key: String, serializer: KSerializer): PubSubChannel = known.getOrPut(key) {
val s = MutableSharedFlow(0)
object : PubSubChannel, Flow by s, FlowCollector by s {}
} as PubSubChannel
override fun string(key: String): PubSubChannel = get(key, String.serializer())
}