Rewrite a paragraph in README

This commit is contained in:
Kai S. K. Engelbart 2021-01-03 17:00:20 +01:00
parent d098b83d85
commit 8b1e3a8c4a
Signed by: Käfer & Engelbart Git
GPG Key ID: 70F2F9206EDC1FCE
1 changed files with 8 additions and 8 deletions

View File

@ -102,27 +102,27 @@ Make sure that you **do not** declare both a parameter and the `eventType` value
## Event consumption ## Event consumption
There are cases when it would be useful to stop event propagation after a certain condition has been fulfilled. In some cases it might be useful to stop the propagation of an event.
Event Bus provides a mechanism to consume events: Event Bus makes this possible with event consumption:
```java ```java
@Event(eventType = SimpleEvent.class, priority=1000) @Event(eventType = SimpleEvent.class, priority=100)
private void onSimpleEvent() { private void onSimpleEvent() {
EventBus.getInstance().cancel(); EventBus.getInstance().cancel();
} }
@Event(eventType = SimpleEvent.class, priority=900) @Event(eventType = SimpleEvent.class, priority=50)
private void onSimpleEvent2() { private void onSimpleEvent2() {
System.out.println("Will not be printed!"); System.out.println("Will not be printed!");
} }
``` ```
In this example, the second method will not be executed as the event will no longer be forwarded. In this example, the second method will not be executed as it has a lower priority and the event will not be propagated after consumption.
Any event handler with a lower priority than the one canceling it will not get executed. This applies to all event handlers that would have been executed after the one consuming the event.
**Important:** **Important:**
Please avoid cancelling events when (multiple) event handlers have the same priority as the one cancelling it: Avoid cancelling events while using multiple event handlers with the same priority.
It is undefined whether those will be executed or not. As event handlers are ordered by priority, it is not defined which of them will be executed after the event has been consumed.
## Installation ## Installation