Object EventBus

  • All Implemented Interfaces:

    
    public class EventBus
    
                        

    Simple event bus for publishing and subscribing to Kobots events. Flows are buffered to 100 events to avoid suspending publishers.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Logger logger
      public final static EventBus INSTANCE
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • 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 to
        onEvent - the function to call when an event is received