List of utility methods to do Duration Calculate
void | runAfter(Duration duration, Runnable toRun) Schedules a runnable after a given time final CompletableFuture<Void> promise = new CompletableFuture<>(); scheduler.schedule(toRun::run, duration.toMillis(), TimeUnit.MILLISECONDS); |
String | seconds(Duration duration) A helper method to get the seconds from a given duration. return String.valueOf(duration.getSeconds());
|
String | serializeDuration(Duration duration) serialize Duration if (duration == null || duration.isNegative() || duration.isZero()) { return ""; Duration remainingTime = duration; StringBuffer sb = new StringBuffer("P"); long days = remainingTime.toDays(); if (days > 0) { sb.append(days).append("D"); ... |
void | sleep(Duration duration) Wrapper around Thread.sleep() that throws RuntimeException if the thread is interrupted. try { Thread.sleep(duration.toMillis()); } catch (InterruptedException e) { throw new RuntimeException(e); |
void | sleep(final Duration duration) TODO: Documentation try { Thread.sleep(duration.toMillis()); } catch (final InterruptedException e) { e.printStackTrace(); |
CompletableFuture | within(CompletableFuture Takes a completable future, and ensures that it completes within a certain duration. final CompletableFuture<T> timeout = failAfter(duration); return future.applyToEither(timeout, Function.identity()); |