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