Schedule a task to be run when the deadline expires. Note if this deadline was created with a custom Ticker, the scheduler's underlying clock should be synchronized with that Ticker. Otherwise the task won't be run at the expected point of time. @param task to run on expiration
(Runnable task, ScheduledExecutorService scheduler)
| 193 | * @return {@link ScheduledFuture} which can be used to cancel execution of the task |
| 194 | */ |
| 195 | public ScheduledFuture<?> runOnExpiration(Runnable task, ScheduledExecutorService scheduler) { |
| 196 | requireNonNull(task, "task"); |
| 197 | requireNonNull(scheduler, "scheduler"); |
| 198 | return scheduler.schedule(task, deadlineNanos - ticker.nanoTime(), TimeUnit.NANOSECONDS); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public String toString() { |