All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nytimes.android.external.cache.Uninterruptibles Maven / Gradle / Ivy

There is a newer version: 3.0.0-alpha
Show newest version
package com.nytimes.android.external.cache;

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() {} }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy