summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/util/Wait.java
blob: f726835be1dab2a92359487bd60dac732bf9fb9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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();
            if (Thread.interrupted())
                throw new InterruptedException();
            elapsed = Duration.between(start, Instant.now());
        } while (elapsed.compareTo(dur) < 0);
    }
}