Skip to content

Commit

Permalink
Merge 6f2856e into bcca6e2
Browse files Browse the repository at this point in the history
  • Loading branch information
no2chem committed Dec 11, 2017
2 parents bcca6e2 + 6f2856e commit 20c34f1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions runtime/src/main/java/org/corfudb/util/CFUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public static <T> T getUninterruptibly(Future<T> future) {
RuntimeException.class, RuntimeException.class);
}

/** A static timeout exception that we complete futures exceptionally with. */
static final TimeoutException TIMEOUT_EXCEPTION = new TimeoutException();

/**
* Generates a completable future which times out.
* inspired by NoBlogDefFound: http://www.nurkiewicz.com/2014/12/asynchronous-timeouts-with.html
Expand All @@ -102,11 +105,8 @@ public static <T> T getUninterruptibly(Future<T> future) {
*/
public static <T> CompletableFuture<T> failAfter(Duration duration) {
final CompletableFuture<T> promise = new CompletableFuture<>();
scheduler.schedule(() -> {
final TimeoutException ex = new TimeoutException("Timeout after "
+ duration.toMillis() + " ms");
return promise.completeExceptionally(ex);
}, duration.toMillis(), TimeUnit.MILLISECONDS);
scheduler.schedule(() -> promise.completeExceptionally(TIMEOUT_EXCEPTION),
duration.toMillis(), TimeUnit.MILLISECONDS);
return promise;
}

Expand Down

0 comments on commit 20c34f1

Please sign in to comment.