Returns the result of the input Future, which must have already completed. The benefits of this method are twofold. First, the name "getDone" suggests to readers that the Future is already done. Second, if buggy code calls getDone on a Future that is still pending
(Future<V> future)
| 1176 | */ |
| 1177 | |
| 1178 | @CanIgnoreReturnValue |
| 1179 | // TODO(cpovirk): Consider calling getDone() in our own code. |
| 1180 | public static <V> V getDone(Future<V> future) |
| 1181 | throws ExecutionException { |
| 1182 | /* |
| 1183 | * We throw IllegalStateException, since the call could succeed later. Perhaps we "should" throw |
| 1184 | * IllegalArgumentException, since the call could succeed with a different argument. Those |
| 1185 | * exceptions' docs suggest that either is acceptable. Google's Java Practices page recommends |
| 1186 | * IllegalArgumentException here, in part to keep its recommendation simple: Static methods |
| 1187 | * should throw IllegalStateException only when they use static state. |
| 1188 | * |
| 1189 | * |
| 1190 | * Why do we deviate here? The answer: We want for fluentFuture.getDone() to throw the same |
| 1191 | * exception as Futures.getDone(fluentFuture). |
| 1192 | */ |
| 1193 | checkState(future.isDone(), "Future was expected to be done: %s", future); |
| 1194 | return getUninterruptibly(future); |
| 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * Returns the result of {@link Future#get()}, converting most exceptions to a new instance of the |
no test coverage detected