class Async::Timeout
@public Since *Async v2.24*.
Represents a flexible timeout that can be rescheduled or extended.
def adjust(duration)
@parameter duration [Numeric] The duration to adjust the timeout by, in seconds.
The duration is relative to the timeout time, e.g. adjusting the timeout by 5 increases the current duration by 5 seconds.
Adjust the timeout by the specified duration.
def adjust(duration) self.reschedule(time + duration) end
def cancel!
def cancel! @handle.cancel! end
def cancelled?
def cancelled? @handle.cancelled? end
def duration
def duration @handle.time - @timers.now end
def duration=(value)
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.
Update the duration of the timeout.
def duration=(value) self.reschedule(@timers.now + value) end
def initialize(timers, handle)
def initialize(timers, handle) @timers = timers @handle = handle end
def now
def now @timers.now end
def reschedule(time)
@parameter time [Numeric] The new time to schedule the timeout for.
Reschedule the timeout to occur at the specified time.
def reschedule(time) k = @handle&.block e.cancel! e = @timers.schedule(time, block) time CancelledError, "Cannot reschedule a cancelled timeout!"
def time
def time @handle.time end
def time=(value)
@parameter value [Numeric] The new time to assign to the timeout.
Assign a new time to the timeout, rescheduling it if necessary.
def time=(value) self.reschedule(value) end