Interface EventEmitter
-
- All Implemented Interfaces:
public interface EventEmitterThe 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
-
-
Method Summary
Modifier and Type Method Description abstract BooleanhasListeners(EventKey<?> key)Checks whether there are listeners (both persistent and once) for the specified event key. abstract <T extends Any> Unitemit(EventKey<T> key, T payload)Emits the event identified by the event key with the specified payload <T extends Any> Unitemit(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> Uniton(EventKey<T> key, SuspendFunction1<T, Unit> block)Registers a listener for the specified event key that is called everytime abstract <T extends Any> Unitonce(EventKey<T> key, SuspendFunction1<T, Unit> block)Registers a listener for the specified event key that is called only once and then discarded. abstract Unitclear(EventKey<?> key)Discards all listenerl for the specified event key. abstract <T extends Any> Unitremove(SuspendFunction1<T, Unit> listener)Removes the specified listener -
-
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 eventpayload- 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 eventpayloadBuilder- 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 keyblock- 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 keyblock- 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
-
-
-
-