Created
April 18, 2012 15:25
-
-
Save ripper234/2414323 to your computer and use it in GitHub Desktop.
Resolved Future
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.Future; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.TimeoutException; | |
/** | |
* Used when you need to return a Future, but you already have the answer. | |
*/ | |
public class ResolvedFuture<T> implements Future<T>{ | |
private final T item; | |
public ResolvedFuture(T item) { | |
this.item = item; | |
} | |
@Override | |
public boolean cancel(boolean mayInterruptIfRunning) { | |
return false; | |
} | |
@Override | |
public boolean isCancelled() { | |
return false; | |
} | |
@Override | |
public boolean isDone() { | |
return true; | |
} | |
@Override | |
public T get() throws InterruptedException, ExecutionException { | |
return item; | |
} | |
@Override | |
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | |
return item; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment