Skip to content
Browse files

Add WaitUntil.orReturn()

  • Loading branch information...
1 parent b8ee465 commit 14304b29f5f095758d6bd916f0464da7cc9cae86 @thomas-kielbus thomas-kielbus committed Jun 12, 2014
Showing with 15 additions and 0 deletions.
  1. +15 −0 hank-core/src/main/java/com/liveramp/hank/util/WaitUntil.java
View
15 hank-core/src/main/java/com/liveramp/hank/util/WaitUntil.java
@@ -25,6 +25,21 @@ public static void condition(Condition condition) throws InterruptedException {
}
}
+ public static boolean orReturn(Condition condition) throws InterruptedException {
+ return orReturn(condition, ExponentialBackoff.DEFAULT_MAXIMUM_BACKOFF_MS);
+ }
+
+ public static boolean orReturn(Condition condition, long maximumBackoffMs) throws InterruptedException {
+ ExponentialBackoff exponentialBackoff = new ExponentialBackoff(ExponentialBackoff.DEFAULT_INITIAL_BACKOFF_MS, maximumBackoffMs);
+ while (!condition.test()) {
+ if (exponentialBackoff.isMaxedOut()) {
+ return false;
+ }
+ exponentialBackoff.backoff();
+ }
+ return true;
+ }
+
public static void orDie(Condition condition) throws InterruptedException {
orDie(condition, ExponentialBackoff.DEFAULT_MAXIMUM_BACKOFF_MS);
}

0 comments on commit 14304b2

Please sign in to comment.
Something went wrong with that request. Please try again.