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

commonMain.com.caesarealabs.rpc4k.runtime.api.EventManager.kt Maven / Gradle / Ivy

There is a newer version: 0.13.0
Show newest version
package com.caesarealabs.rpc4k.runtime.api

import kotlin.jvm.JvmInline


@JvmInline
public value class EventConnection (
    public val id: String
//    public suspend fun send(bytes: ByteArray)
)

public interface EventManager {
    //TODO: consider validating subscriptions. Maybe benchmark how much time it takes. It's a good idea for correctness
    // but not that important.
    public suspend fun subscribe(subscription: C2SEventMessage.Subscribe, connection: EventConnection)

    /**
     * Returns whether there was something to actually unsubscribe to matching the criteria.
     */
    public suspend fun unsubscribe(event: String, listenerId: String): Boolean

    /**
     * Returns subscriptions to the given event, watching the given object id
     * @param target If a non-null value is provided then only subscriptions matching that target will be returned
     * if null is passed, all subscriptions of the event will be returned.
     */
    public suspend fun match(event: String, target: String?): List

    /**
     * Removes all subscriptions of the given connection
     */
    public suspend fun dropClient(connection: EventConnection)
}

public data class EventSubscription(val connection: EventConnection, val info: C2SEventMessage.Subscribe)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy