class Async::Timeout

@public Since *Async v2.24*.
Represents a flexible timeout that can be rescheduled or extended.

def adjust(duration)

@returns [Numeric] The new time at which the timeout will occur.
@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!

Cancel the timeout, preventing it from executing.
def cancel!
	@handle.cancel!
end

def cancelled?

@returns [Boolean] Whether the timeout has been cancelled.
def cancelled?
	@handle.cancelled?
end

def duration

@returns [Numeric] The time remaining until the timeout occurs, in seconds.
def duration
	@handle.time - @timers.now
end

def duration=(value)

@parameter value [Numeric] The new duration to assign to the timeout, in seconds.

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)

Initialize a new timeout.
def initialize(timers, handle)
	@timers = timers
	@handle = handle
end

def now

@returns [Numeric] The current time in the scheduler, relative to the time of this timeout, in seconds.
def now
	@timers.now
end

def reschedule(time)

@returns [Numeric] The new time at which the timeout will occur.
@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

@returns [Numeric] The time at which the timeout will occur, in seconds since {now}.
def time
	@handle.time
end

def time=(value)

@returns [Numeric] The new time at which the timeout will occur.
@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