class Guavate {

  public static <T> CompletableFuture<T> poll(
      ScheduledExecutorService executorService,
      Duration initialDelay,
      Duration frequency,
      Supplier<T> pollingTask) {

    CompletableFuture<T> result = new CompletableFuture<>();
    Runnable decoratedPollingTask = () -> pollTask(pollingTask, result);
    ScheduledFuture<?> scheduledTask = executorService.scheduleAtFixedRate(
        decoratedPollingTask, initialDelay.toMillis(), frequency.toMillis(), TimeUnit.MILLISECONDS);
    return result.whenComplete((r, ex) -> scheduledTask.cancel(true));
  }

  private  Guavate();

}