diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-15 17:12:19 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-15 17:12:19 -0500 |
| commit | 2358dd5b33162d9bd66b71cbf6b74b453796739f (patch) | |
| tree | d89293289354fe929737df92b5d321115e58e855 /src/main/java/derms/util/Wait.java | |
| parent | 3f63da76ab16450694d84dd29503d2e7ec0198c8 (diff) | |
| download | soen423-2358dd5b33162d9bd66b71cbf6b74b453796739f.zip | |
move Wait to util package
Diffstat (limited to 'src/main/java/derms/util/Wait.java')
| -rw-r--r-- | src/main/java/derms/util/Wait.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/derms/util/Wait.java b/src/main/java/derms/util/Wait.java new file mode 100644 index 0000000..1e77020 --- /dev/null +++ b/src/main/java/derms/util/Wait.java @@ -0,0 +1,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); + } +} |