feat: unregisterListener

This commit is contained in:
zaaarf 2023-08-23 23:50:24 +02:00
parent fd87c90d63
commit b68b0cb0f6
No known key found for this signature in database
GPG key ID: 6445A5CD15E5B40C
2 changed files with 18 additions and 0 deletions

View file

@ -43,6 +43,15 @@ public class GEB implements IBus {
this.listenerMap.put(listener.getClass(), listener); this.listenerMap.put(listener.getClass(), listener);
} }
/**
* Unregister a listener from the bus.
* @param listener the listener
*/
@Override
public void unregisterListener(IListener listener) {
this.listenerMap.remove(listener.getClass());
}
/** /**
* Dispatches an event, calling all of its listeners that are subscribed to this bus. * Dispatches an event, calling all of its listeners that are subscribed to this bus.
* @param event the event to fire * @param event the event to fire

View file

@ -12,6 +12,15 @@ public interface IBus {
*/ */
void registerListener(IListener listener); void registerListener(IListener listener);
/**
* Unregister a listener from the bus.
* While sensible implementations can get this quite fast, it's generally
* faster to use {@link IListener#isActive()}, so only use this if you
* *mean* to unregister for good.
* @param listener the listener
*/
void unregisterListener(IListener listener);
/** /**
* Dispatches an event, calling all of its listeners that are subscribed to this bus. * Dispatches an event, calling all of its listeners that are subscribed to this bus.
* @param event the event to fire * @param event the event to fire