Merge pull request #284 from AlexanderBielen/feature/minimum-conditional-sleep-time

Added conditional sleep with minimum timeout
This commit is contained in:
Jeroen Ketelaar
2018-10-26 12:41:33 -05:00
committed by GitHub
@@ -53,6 +53,30 @@ public final class Time {
return true;
}
/**
* Sleeps until SleepCondition is valid, but with a minimum timeout.
*
* @param conn the condition.
* @param timeout the time in milliseconds before it stops sleeping.
* @param minimumTimeout the minimum time to sleep.
*
* @return whether it ran successfully without timing out.
*/
public static boolean sleep(SleepCondition conn, int timeout, int minimumTimeout) {
long start = System.currentTimeMillis();
if(!sleep(conn, timeout)) {
return false;
}
long t;
if((t = System.currentTimeMillis() - start) < minimumTimeout) {
Time.sleep((int)(minimumTimeout - t));
}
return true;
}
/**
* Gets current time in milliseconds
*