mirror of https://github.com/apache/lucene.git
SOLR-12087: Fixed bug in TimeOut.waitFor that can cause an infinite loop and added javadocs
This commit is contained in:
parent
07d255a708
commit
b0f677c383
|
@ -51,9 +51,16 @@ public class TimeOut {
|
|||
return unit.convert(timeSource.getTimeNs() - startTime, NANOSECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the given {@link Supplier} returns true or the time out expires which ever happens first
|
||||
* @param messageOnTimeOut the exception message to be used in case a TimeoutException is thrown
|
||||
* @param supplier a {@link Supplier} that returns a {@link Boolean} value
|
||||
* @throws InterruptedException if any thread has interrupted the current thread
|
||||
* @throws TimeoutException if the timeout expires
|
||||
*/
|
||||
public void waitFor(String messageOnTimeOut, Supplier<Boolean> supplier)
|
||||
throws InterruptedException, TimeoutException {
|
||||
while (!supplier.get() && hasTimedOut()) {
|
||||
while (!supplier.get() && !hasTimedOut()) {
|
||||
Thread.sleep(500);
|
||||
}
|
||||
if (hasTimedOut()) throw new TimeoutException(messageOnTimeOut);
|
||||
|
|
Loading…
Reference in New Issue