com.nytimes.android.external.cache3.Uninterruptibles Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cache3 Show documentation
Show all versions of cache3 Show documentation
Store3 is built with RxJava2
package com.nytimes.android.external.cache3;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
public final class Uninterruptibles {
/**
* Invokes {@code future.}{@link Future#get() get()} uninterruptibly.
* To get uninterruptibility and remove checked exceptions, see
* @link Futures#getUnchecked}.
*
* If instead, you wish to treat {@link InterruptedException} uniformly
* with other exceptions, see @link Futures#getChecked(Future, Class)
* Futures.getChecked}.
*
* @throws ExecutionException if the computation threw an exception
*/
public static V getUninterruptibly(@Nonnull Future future)
throws ExecutionException {
boolean interrupted = false;
try {
while (true) {
try {
return future.get();
} catch (InterruptedException e) {
interrupted = true;
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
private Uninterruptibles() {}
}