class EventBus implements Subscriber, Publisher {

  @Override
  public void publish(Event<?> event) {
    Preconditions.checkNotNull(event);

    synchronized (this) {
      if (pendingEvents != null) {
        pendingEvents.add(event);
        return;
      }
    }

    for (Map.Entry<EventHandler<Object>, Executor> handlerData : getHandlers(event)) {
      // the casted call is safe since type-safety is guaranteed by the signature of #subscribe().
      @SuppressWarnings("unchecked")
      Event<Object> casted = (Event<Object>) event;
      handlerData.getValue().execute(() -> handlerData.getKey().handle(casted));
    }
  }

    EventBus(Executor defaultExecutor);

}