class Timeout
Represents a flexible timeout that can be rescheduled or extended.
Signature
- public
Since Async v2.24.
Nested
Definitions
def initialize(timers, handle)
Initialize a new timeout.
Implementation
def initialize(timers, handle)
@timers = timers
@handle = handle
end
def duration
Signature
-
returns
Numeric
The time remaining until the timeout occurs, in seconds.
Implementation
def duration
@handle.time - @timers.now
end
def duration=(value)
Update the duration of the timeout.
The duration is relative to the current time, e.g. setting the duration to 5 means the timeout will occur in 5 seconds from now.
Signature
-
parameter
value
Numeric
The new duration to assign to the timeout, in seconds.
Implementation
def duration=(value)
self.reschedule(@timers.now + value)
end
def adjust(duration)
Adjust the timeout by the specified duration.
The duration is relative to the timeout time, e.g. adjusting the timeout by 5 increases the current duration by 5 seconds.
Signature
-
parameter
duration
Numeric
The duration to adjust the timeout by, in seconds.
-
returns
Numeric
The new time at which the timeout will occur.
Implementation
def adjust(duration)
self.reschedule(time + duration)
end
def time
Signature
-
returns
Numeric
The time at which the timeout will occur, in seconds since
Async::Timeout#now
.
Implementation
def time
@handle.time
end
def time=(value)
Assign a new time to the timeout, rescheduling it if necessary.
Signature
-
parameter
value
Numeric
The new time to assign to the timeout.
-
returns
Numeric
The new time at which the timeout will occur.
Implementation
def time=(value)
self.reschedule(value)
end
def now
Signature
-
returns
Numeric
The current time in the scheduler, relative to the time of this timeout, in seconds.
Implementation
def now
@timers.now
end
def cancel!
Cancel the timeout, preventing it from executing.
Implementation
def cancel!
@handle.cancel!
end
def cancelled?
Signature
-
returns
Boolean
Whether the timeout has been cancelled.
Implementation
def cancelled?
@handle.cancelled?
end