Skip to content

Commit

Permalink
Added synchronize blocks on access of openedMenuViews (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jul 20, 2023
1 parent 464343c commit 5675309
Showing 1 changed file with 18 additions and 8 deletions.
Expand Up @@ -85,7 +85,9 @@ public CompletableFuture<V> createView(SuperiorPlayer superiorPlayer, A args) {

@Override
public void refreshViews() {
openedMenuViews.forEach(V::refreshView);
synchronized (openedMenuViews) {
openedMenuViews.forEach(V::refreshView);
}
}

@Override
Expand All @@ -95,7 +97,9 @@ public void refreshViews(Predicate<V> viewFilter) {

@Override
public void closeViews() {
openedMenuViews.forEach(V::closeView);
synchronized (openedMenuViews) {
openedMenuViews.forEach(V::closeView);
}
}

@Override
Expand All @@ -104,18 +108,24 @@ public void closeViews(Predicate<V> viewFilter) {
}

public void addView(V view) {
openedMenuViews.add(view);
synchronized (openedMenuViews) {
openedMenuViews.add(view);
}
}

public void removeView(V view) {
openedMenuViews.remove(view);
synchronized (openedMenuViews) {
openedMenuViews.remove(view);
}
}

protected final void filterViews(Predicate<V> viewFilter, Consumer<V> onMatch) {
openedMenuViews.forEach(view -> {
if (viewFilter.test(view))
onMatch.accept(view);
});
synchronized (openedMenuViews) {
openedMenuViews.forEach(view -> {
if (viewFilter.test(view))
onMatch.accept(view);
});
}
}

@Override
Expand Down

0 comments on commit 5675309

Please sign in to comment.