Object EventBus
-
- All Implemented Interfaces:
public class EventBusSimple event bus for publishing and subscribing to Kobots events. Flows are buffered to 100 events to avoid suspending publishers.
-
-
Method Summary
Modifier and Type Method Description final SharedFlow<KobotsEvent>getFlow(Class<out KobotsEvent> eventClass)Get the flow for the given event class. final <T extends KobotsEvent> Unitpublish(T event)Publish an event to the event bus. final <T extends KobotsEvent> Unitsubscribe(String name, SuspendFunction1<T, Unit> onEvent)Subscribe to events of type T with the given name. final LoggergetLogger()-
-
Method Detail
-
getFlow
final SharedFlow<KobotsEvent> getFlow(Class<out KobotsEvent> eventClass)
Get the flow for the given event class. Public due to inline reified subscribe function. Note that the flow is created if it does not already exist, but this still only returns a non-modifiable flow.
- Parameters:
eventClass- the class of the event
-
publish
final <T extends KobotsEvent> Unit publish(T event)
Publish an event to the event bus.
- Parameters:
event- the event to publish
-
subscribe
final <T extends KobotsEvent> Unit subscribe(String name, SuspendFunction1<T, Unit> onEvent)
Subscribe to events of type T with the given name. Messages are delivered concurrently within the limits of the buffer size of the underlying flow.
- Parameters:
name- the name of the event to subscribe toonEvent- the function to call when an event is received
-
getLogger
final Logger getLogger()
-
-
-
-