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

commonMain.events.SubscriberImpl.kt Maven / Gradle / Ivy

package events

class SubscriberImpl(
    topic: String,
    private val callback: EventCallback,
    private val container: MutableList>
) : Subscriber(topic) {
    override fun invoke(data: D) = try {
        callback(data)
    } catch (err: ClassCastException) {
        throw SubscriptionException("Subscriber of topic $topic did not subscribe to get data of type ${data!!::class.simpleName}", err)
    }

    override fun unsubscribe() {
        container.remove(this as Subscriber)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy