Package io.v47.events

Interface EventEmitter

  • All Implemented Interfaces:

    
    public interface EventEmitter
    
                        

    The event emitter asynchronously calls the listeners for the specified event key and provides the specified payload to them.

    It's possible to add listeners that are called everytime, and some that are only called once and then removed.

    Since:

    Events 1.0

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract Boolean hasListeners(EventKey<?> key) Checks whether there are listeners (both persistent and once) for the specified event key.
      abstract <T extends Any> Unit emit(EventKey<T> key, T payload) Emits the event identified by the event key with the specified payload
      <T extends Any> Unit emit(EventKey<T> key, Function0<T> payloadBuilder) Emits the event identified by the event with the payload created by the specified builder.
      abstract <T extends Any> Unit on(EventKey<T> key, SuspendFunction1<T, Unit> block) Registers a listener for the specified event key that is called everytime
      abstract <T extends Any> Unit once(EventKey<T> key, SuspendFunction1<T, Unit> block) Registers a listener for the specified event key that is called only once and then discarded.
      abstract Unit clear(EventKey<?> key) Discards all listenerl for the specified event key.
      abstract <T extends Any> Unit remove(SuspendFunction1<T, Unit> listener) Removes the specified listener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • hasListeners

         abstract Boolean hasListeners(EventKey<?> key)

        Checks whether there are listeners (both persistent and once) for the specified event key.

        Parameters:
        key - The key uniquely identifying an event
        Since:

        Events 2.1

      • emit

         abstract <T extends Any> Unit emit(EventKey<T> key, T payload)

        Emits the event identified by the event key with the specified payload

        Parameters:
        key - The key uniquely identifying the event
        payload - Data that is passed to the listeners
        Since:

        Events 1.0

      • emit

         <T extends Any> Unit emit(EventKey<T> key, Function0<T> payloadBuilder)

        Emits the event identified by the event with the payload created by the specified builder.

        The emitter may choose to not even call the builder if there are no listeners for the specified event key.

        This is useful when the payload is rather expensive to build, and it's not certain there will be a listener for that particular event key

        Parameters:
        key - The key uniquely identifying the event
        payloadBuilder - The function building the actual payload
        Since:

        Events 2.1

      • on

         abstract <T extends Any> Unit on(EventKey<T> key, SuspendFunction1<T, Unit> block)

        Registers a listener for the specified event key that is called everytime

        Parameters:
        key - The event key
        block - The listener for the event's payload
        Since:

        Events 1.0

      • once

         abstract <T extends Any> Unit once(EventKey<T> key, SuspendFunction1<T, Unit> block)

        Registers a listener for the specified event key that is called only once and then discarded.

        Parameters:
        key - The event key
        block - The listener for the event's payload
        Since:

        Events 1.0

      • clear

         abstract Unit clear(EventKey<?> key)

        Discards all listenerl for the specified event key.

        If not key is specified all listeners are discarded.

        Parameters:
        key - The event key
        Since:

        Events 1.0