Skip to content

Commit

Permalink
Fix to make SetActionMultiplexer thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Jun 13, 2021
1 parent d90d517 commit 9d98e4b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/me/retrodaredevil/action/SetActionMultiplexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,18 @@ protected void onIsDoneRequest() {
@Override
protected void onUpdate() {
super.onUpdate();
for (Iterator<Action> iterator = actionSet.iterator(); iterator.hasNext(); ) {
Action action = iterator.next();
final List<Action> actions;
synchronized (this) {
actions = new ArrayList<>(actionSet);
}
for (Action action : actions) {
action.update();
if(action.isDone()){
if (action.isDone()) {
action.end();
iterator.remove();
} else if(!action.isActive()){
synchronized (this) {
actionSet.remove(action);
}
} else if (!action.isActive()) {
throw new IllegalStateException(action + " is not active when it should be!");
}
}
Expand Down

0 comments on commit 9d98e4b

Please sign in to comment.