MCPcopy Create free account
hub / github.com/traneio/future / WithinPromise

Class WithinPromise

future-java/src/main/java/io/trane/future/Promise.java:799–834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

797 }
798
799 private static final class WithinPromise<T> extends Promise<T> implements Responder<T>, Runnable {
800
801 private final InterruptHandler handler;
802 private final ScheduledFuture<?> task;
803 private final Throwable exception;
804
805 public WithinPromise(final InterruptHandler handler, final Duration timeout,
806 final ScheduledExecutorService scheduler, final Throwable exception) {
807 this.handler = handler;
808 this.task = scheduler.schedule(this, timeout.toMillis(), TimeUnit.MILLISECONDS);
809 this.exception = exception;
810 }
811
812 @Override
813 public final void onException(final Throwable ex) {
814 task.cancel(false);
815 becomeIfEmpty(Future.exception(ex));
816 }
817
818 @Override
819 public final void onValue(final T value) {
820 task.cancel(false);
821 becomeIfEmpty(Future.value(value));
822 }
823
824 @Override
825 public final void run() {
826 handler.raise(exception);
827 becomeIfEmpty(Future.exception(exception));
828 }
829
830 @Override
831 protected final InterruptHandler getInterruptHandler() {
832 return handler;
833 }
834 }
835
836 @Override
837 public final Future<T> within(final Duration timeout, final ScheduledExecutorService scheduler,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…