code: public static <T> CompletableFuture<T> futureWithTimeout(Duration timeout, String tag, ScheduledExecutorService executorService) {
          CompletableFuture<T> result = new CompletableFuture<>();
          ScheduledFuture<Boolean> sf = executorService.schedule(() -> result.completeExceptionally(new TimeoutException(tag)), timeout.toMillis(), TimeUnit.MILLISECONDS);
          result.whenComplete((r, ex) -> sf.cancel(true));
          return result;
      }
docs: Creates a new CompletableFuture that will timeout after the given amount of time.
  
  @param timeout         The timeout for the future.
  @param tag             A tag (identifier) to be used as a parameter to the TimeoutException.
  @param executorService An ExecutorService that will be used to invoke the timeout on.
  @param <T>             The Type argument for the CompletableFuture to create.
  @return The result.