code: void invokeAndWait(final Runnable r) {
          final CountDownLatch latch = new CountDownLatch(1);
          queue.postRunnable(() -> {
              try {
                  r.run();
              } finally {
                  latch.countDown();
              }
          });
          try {
              latch.await();
          } catch (InterruptedException e) { }
      }
docs: Posts a Runnable to the JavaFX event queue and waits for the Runnable
  to complete.
  
  @param r an action to be performed on the JavaFX application thread.