static <K,V,X extends Throwable> Map<K,V> |
MoreFutures.tryWait(Iterable<K> keys,
long timeout,
TimeUnit unit,
ThrowableFunction<K,Future<V>,X> asyncFunc) |
A typical usage:
<pre>
// a fail-safe example
List<Integer> list = getSomeIds();
Map<Integer, User> success;
try {
success = tryWait(list, 1, SECONDS, id -> executor.submit(() -> retrieve(id)));
} catch (TryWaitUncheckedException e) {
success = e.getSuccess(); // there are still some success
}
// a fail-fast example
List<Integer> list = getSomeIds();
// don't try/catch the exception it throws.
Map<Integer, User> success = tryWait(list, 1, SECONDS, id -> executor.submit(() -> retrieve(id)));
</pre>
|