Skip to content

Commit

Permalink
Add AbstractScheduledService.Schedule(Duration).
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 417651818
  • Loading branch information
kluever authored and Google Java Core Libraries committed Dec 21, 2021
1 parent a3e411c commit 448e326
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.util.concurrent.Internal.toNanosSaturated;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.NANOSECONDS;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Supplier;
Expand Down Expand Up @@ -128,7 +129,7 @@ public abstract static class Scheduler {
*/
public static Scheduler newFixedDelaySchedule(Duration initialDelay, Duration delay) {
return newFixedDelaySchedule(
toNanosSaturated(initialDelay), toNanosSaturated(delay), TimeUnit.NANOSECONDS);
toNanosSaturated(initialDelay), toNanosSaturated(delay), NANOSECONDS);
}

/**
Expand Down Expand Up @@ -165,7 +166,7 @@ public Cancellable schedule(
*/
public static Scheduler newFixedRateSchedule(Duration initialDelay, Duration period) {
return newFixedRateSchedule(
toNanosSaturated(initialDelay), toNanosSaturated(period), TimeUnit.NANOSECONDS);
toNanosSaturated(initialDelay), toNanosSaturated(period), NANOSECONDS);
}

/**
Expand Down Expand Up @@ -722,6 +723,14 @@ public Schedule(long delay, TimeUnit unit) {
this.delay = delay;
this.unit = checkNotNull(unit);
}

/**
* @param delay the time from now to delay execution
* @since NEXT
*/
public Schedule(Duration delay) {
this(toNanosSaturated(delay), NANOSECONDS);
}
}

/**
Expand Down

0 comments on commit 448e326

Please sign in to comment.