Skip to content

Instantly share code, notes, and snippets.

@dcapwell
Created April 30, 2013 22:31
Show Gist options
  • Save dcapwell/5492453 to your computer and use it in GitHub Desktop.
Save dcapwell/5492453 to your computer and use it in GitHub Desktop.
@Override
public C get(final long timeout, final TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException {
try {
return super.get(timeout, unit);
} catch (TimeoutException e) {
Function<List<Optional<V>>, C> localCombiner = combiner;
if (localCombiner != null) {
// if the set took or not we don't care, if it doesn't take it means that it was set by the last future.
set(localCombiner.apply(values));
} else {
// if combiner is null, then we should be done and have data.
checkState(isDone());
}
// ether the state is messed up and an exception is thrown, or set was called which means data is present
// this shouldn't block.
return super.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment