summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/util/Wait.java
blob: 1e77020c34746ad7ac143be2f2c55cd5c93695ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package derms.util;

import java.time.Duration;
import java.time.Instant;

public class Wait {
    /** Yield the thread for the specified duration. */
    public static void forDuration(Duration dur) throws InterruptedException {
        Instant start = Instant.now();
        Duration elapsed;
        do {
            Thread.yield();
            elapsed = Duration.between(start, Instant.now());
        } while (elapsed.compareTo(dur) < 0);
    }
}