mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 16:50:39 +00:00
Added conditional sleep with minimum timeout
This commit is contained in:
@@ -53,6 +53,30 @@ public final class Time {
|
|||||||
return true;
|
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();
|
||||||
|
while (!conn.isValid()) {
|
||||||
|
if (start + timeout < System.currentTimeMillis()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Time.sleep(50);
|
||||||
|
}
|
||||||
|
long t;
|
||||||
|
if((t = System.currentTimeMillis() - start) < minimumTimeout) {
|
||||||
|
Time.sleep((int)(minimumTimeout - t));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets current time in milliseconds
|
* Gets current time in milliseconds
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user