How much time is remaining in the specified time unit. Internal units are maintained as nanoseconds and conversions are subject to the constraints documented for TimeUnit#convert. If there is no time remaining, the returned duration is how long ago the deadline expired.
(TimeUnit unit)
| 174 | * long ago the deadline expired. |
| 175 | */ |
| 176 | public long timeRemaining(TimeUnit unit) { |
| 177 | final long nowNanos = ticker.nanoTime(); |
| 178 | if (!expired && deadlineNanos - nowNanos <= 0) { |
| 179 | expired = true; |
| 180 | } |
| 181 | return unit.convert(deadlineNanos - nowNanos, TimeUnit.NANOSECONDS); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Schedule a task to be run when the deadline expires. |