Skip to content

Commit

Permalink
Add EventWaiter constructor that accepts an ExecutorService
Browse files Browse the repository at this point in the history
  • Loading branch information
BreadMoirai committed Feb 1, 2018
1 parent 07762d2 commit 7f0b83d
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ public class EventWaiter implements EventListener {

private final Map<Class<? extends Event>, List<EventAction>> waitingEvents;

private final ScheduledExecutorService threadpool;
private final ScheduledExecutorService executorService;

public EventWaiter() {
waitingEvents = new HashMap<>();
threadpool = Executors.newSingleThreadScheduledExecutor();
this.waitingEvents = new HashMap<>();
this.executorService = Executors.newSingleThreadScheduledExecutor();
}

public EventWaiter(ScheduledExecutorService executorService) {
this.waitingEvents = new HashMap<>();
this.executorService = executorService;
}

public <T extends Event> EventActionBuilder<T, Void> waitFor(Class<T> eventClass) {
return new EventActionBuilderImpl<>(eventClass, this);
Expand All @@ -63,7 +67,7 @@ void removeAction(Class<? extends Event> eventClass, EventAction action) {
}

ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
return threadpool.schedule(command, delay, unit);
return executorService.schedule(command, delay, unit);
}

private <T extends Event> List<EventAction> getActions(Class<T> eventType) {
Expand Down Expand Up @@ -92,7 +96,7 @@ public final void onEvent(Event event) {
list.removeAll(remove);
}
if (event instanceof ShutdownEvent) {
threadpool.shutdown();
executorService.shutdown();
}
c = c.getSuperclass();
}
Expand Down

0 comments on commit 7f0b83d

Please sign in to comment.