All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.lightningserver.pubsub.LocalPubSub.kt Maven / Gradle / Ivy

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())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy