Skip to content

Commit 448e326

Browse files
klueverGoogle Java Core Libraries
authored andcommitted
Add AbstractScheduledService.Schedule(Duration).
RELNOTES=n/a PiperOrigin-RevId: 417651818
1 parent a3e411c commit 448e326

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

guava/src/com/google/common/util/concurrent/AbstractScheduledService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.common.util.concurrent.Internal.toNanosSaturated;
2121
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
2222
import static java.util.Objects.requireNonNull;
23+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
2324

2425
import com.google.common.annotations.GwtIncompatible;
2526
import com.google.common.base.Supplier;
@@ -128,7 +129,7 @@ public abstract static class Scheduler {
128129
*/
129130
public static Scheduler newFixedDelaySchedule(Duration initialDelay, Duration delay) {
130131
return newFixedDelaySchedule(
131-
toNanosSaturated(initialDelay), toNanosSaturated(delay), TimeUnit.NANOSECONDS);
132+
toNanosSaturated(initialDelay), toNanosSaturated(delay), NANOSECONDS);
132133
}
133134

134135
/**
@@ -165,7 +166,7 @@ public Cancellable schedule(
165166
*/
166167
public static Scheduler newFixedRateSchedule(Duration initialDelay, Duration period) {
167168
return newFixedRateSchedule(
168-
toNanosSaturated(initialDelay), toNanosSaturated(period), TimeUnit.NANOSECONDS);
169+
toNanosSaturated(initialDelay), toNanosSaturated(period), NANOSECONDS);
169170
}
170171

171172
/**
@@ -722,6 +723,14 @@ public Schedule(long delay, TimeUnit unit) {
722723
this.delay = delay;
723724
this.unit = checkNotNull(unit);
724725
}
726+
727+
/**
728+
* @param delay the time from now to delay execution
729+
* @since NEXT
730+
*/
731+
public Schedule(Duration delay) {
732+
this(toNanosSaturated(delay), NANOSECONDS);
733+
}
725734
}
726735

727736
/**

0 commit comments

Comments
 (0)