com.lightningkite.lightningserver.pubsub.PubSub.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 com.lightningkite.lightningserver.core.Disconnectable
import com.lightningkite.lightningserver.serialization.Serialization
import com.lightningkite.lightningserver.serverhealth.HealthCheckable
import com.lightningkite.lightningserver.serverhealth.HealthStatus
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.serialization.KSerializer
import kotlinx.serialization.serializer
@Deprecated("Renamed to just 'PubSub'", ReplaceWith("PubSub", "com.lightningkite.lightningserver.pubsub.PubSub"))
typealias PubSubInterface = PubSub
interface PubSub : HealthCheckable, Disconnectable {
fun get(key: String, serializer: KSerializer): PubSubChannel
fun string(key: String): PubSubChannel
override suspend fun healthCheck(): HealthStatus {
return try {
get("health-check-test-key").emit(true)
HealthStatus(HealthStatus.Level.OK)
} catch (e: Exception) {
HealthStatus(HealthStatus.Level.ERROR, additionalMessage = e.message)
}
}
}
inline operator fun PubSub.get(key: String): PubSubChannel {
return get(key, Serialization.Internal.json.serializersModule.serializer())
}
interface PubSubChannel : Flow, FlowCollector {}