What is the best way to build a complete future in Java? I performed my own CompletedFuture below, but was hoping something similar already existed.
public class CompletedFuture<T> implements Future<T> { private final T result; public CompletedFuture(final T result) { this.result = result; } @Override public boolean cancel(final boolean b) { return false; } @Override public boolean isCancelled() { return false; } @Override public boolean isDone() { return true; } @Override public T get() throws InterruptedException, ExecutionException { return this.result; } @Override public T get(final long l, final TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { return get(); } }
java future
Jake Walsh Dec 13 '12 at 18:56 2012-12-13 18:56
source share