Package co.paralleluniverse.strands
Class Timeout
- java.lang.Object
-
- co.paralleluniverse.strands.Timeout
-
public class Timeout extends java.lang.Object
Represents a timeout that can span several operations. This object expires within a given time from the instant this object has been created. It maintains the time left until it expires, so it can be initialized once and then passed to several consecutive operation, making sure that the sequence of operations completes within the timeout's duration.To use this timeout in methods that take a
long timeout
and aTimeUnit unit
argument, pass:timeout.nanosLeft(), TimeUnit.NANOSECONDS
-
-
Constructor Summary
Constructors Constructor Description Timeout(long timeout, java.util.concurrent.TimeUnit unit)
Starts a newTimeout
that begins now and expires within the given timeout from the instant this constructor has been called.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isExpired()
Tests whether the timeout has expired.long
nanosLeft()
Returns how many nanoseconds are left before the timeout expires, or a negative number indicating how many nanoseconds have elapsed since the timeout expired.long
timeLeft(java.util.concurrent.TimeUnit unit)
Returns how long is left before the timeout expires in the given time unit.
-
-
-
Method Detail
-
nanosLeft
public long nanosLeft()
Returns how many nanoseconds are left before the timeout expires, or a negative number indicating how many nanoseconds have elapsed since the timeout expired.
-
timeLeft
public long timeLeft(java.util.concurrent.TimeUnit unit)
Returns how long is left before the timeout expires in the given time unit.- Parameters:
unit
- the time unit of the return value- Returns:
- how long is left before the timeout expires in the given time unit.
-
isExpired
public boolean isExpired()
Tests whether the timeout has expired.
-
-