- Type Parameters:
T
- the type of data propagated with this event
An event class implementing the
Observer
interface.
Event<Boolean> event = Event.event();
event.addListener(this::doSomething);
event.run();
event.addConsumer(this::onBoolean);
event.accept(true);
The event observer observes the event but can not trigger it.
Observer<Boolean> observer = event.observer();
observer.addListener(this::doSomethingElse);
Listeners and Consumers can be added using a WeakReference
.
observer.addWeakListener(this::doSomethingElse);
observer.addWeakConsumer(this::onBoolean);
Any weak references that no longer refer to a listener/consumer instance
are cleared when listeners are added or removed, but to manually clear these empty
weak references call Observer.removeWeakListener(Runnable)
or Observer.removeWeakConsumer(Consumer)
with a listener/consumer instance which has not been registered on the observer, such as a new one.
observer.removeWeakListener(() -> {});
observer.removeWeakConsumer(value -> {});
A factory for Event
instances via event()
.-
Method Summary
Methods inherited from interface is.codion.common.observer.Observer
addConsumer, addListener, addWeakConsumer, addWeakListener, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener
-
Method Details
-
run
void run()Triggers this event. -
accept
Triggers this event. -
observer
- Returns:
- an observer notified each time this event occurs
-
event
Creates a newEvent
.- Type Parameters:
T
- the type of data propagated to listeners on event occurrence- Returns:
- a new Event
-