class ChromeDevToolsUtils {

  public static <T> void waitForEvent(Function<EventHandler<T>, EventListener> eventConsumer) {
    final CountDownLatch countDownLatch = new CountDownLatch(1);

    final EventListener eventListener =
        eventConsumer.apply(
            event -> {
              countDownLatch.countDown();
            });

    try {
      countDownLatch.await();
    } catch (InterruptedException e) {
      throw new RuntimeException("Interrupted while waiting for event.", e);
    } finally {
      eventListener.unsubscribe();
    }
  }

}