Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy Event internals - use a static priority Comparator #576

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions inject/src/main/java/io/avaje/inject/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
*/
public abstract class Event<T> {

private static final Comparator<Observer<?>> PRIORITY = Comparator.comparing(Observer::priority);

protected final List<Observer<T>> observers;
protected final String defaultQualifier;

Expand All @@ -57,7 +59,7 @@ protected Event(ObserverManager manager, Type type, String qualifier) {
*/
public void fire(T event, String qualifier) {
observers.stream()
.sorted(Comparator.comparing(Observer::priority))
.sorted(PRIORITY)
.forEach(observer -> observer.observe(event, qualifier, false));
}

Expand All @@ -73,7 +75,7 @@ public CompletionStage<T> fireAsync(T event, String qualifier) {
var exceptionHandler = new CollectingExceptionHandler();

return observers.stream()
.sorted(Comparator.comparing(Observer::priority))
.sorted(PRIORITY)
.reduce(CompletableFuture.<Void>completedFuture(null), (future, observer) ->
future.thenRun(() -> {
try {
Expand Down
Loading