docs: @SuppressWarnings("PMD")
    static <T> void schedule(
        ScheduledExecutorService executor, WeakReference<T> ref, long delay, Consumer<T> poll) {
      final AtomicReference<Future<?>> futureRef = new AtomicReference<>();
      final Runnable cancel = () -> {
        Future<?> f = futureRef.get();
        if (f != null) {
          f.cancel(false);
        }
      };
      final Runnable task = () -> {
        try {
          T r = ref.get();
          if (r != null) {
            poll.accept(r);
          } else {
            cancel.run();
          }
        } catch (Throwable t) {
          cancel.run();
        }
      };
      futureRef.set(executor.scheduleWithFixedDelay(task, delay, delay, TimeUnit.MILLISECONDS));
    }