Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add WaitUntil.orReturn()

  • Loading branch information...
commit 14304b29f5f095758d6bd916f0464da7cc9cae86 1 parent b8ee465
@thomas-kielbus thomas-kielbus authored
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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.