public static <T> T withSingleThreadExecutor(@NotNull String name, @NotNull Function<ExecutorService, T> action) {
    ExecutorService executorService = Executors.newSingleThreadExecutor(new SimpleThreadFactory(name));
    try {
      return action.apply(executorService);
    }
    finally {
      executorService.shutdown();
      try {
        executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
      }
      catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  }
public static <T> T withSingleThreadExecutor(@NotNull String name, @NotNull Function<ExecutorService, T> action)