class Async::Deadline

@public Since *Async v2.31*.
Includes an efficient representation for zero (non-blocking) timeouts.
Represents a deadline timeout with decrementing remaining time.

def self.start(timeout)

@returns [Deadline | Nil] A deadline instance, Zero singleton, or nil.
@parameter timeout [Numeric | Nil] The timeout duration, or nil for no timeout.
Create a deadline for the given timeout.
def self.start(timeout)
	if timeout.nil?
		nil
	elsif timeout <= 0
		Zero
	else
		self.new(timeout)
	end
end

def expired?

@returns [Boolean] True if no time remains.
Check if the deadline has expired.
def expired?
	self.remaining <= 0
end

def initialize(remaining)

@parameter remaining [Numeric] The initial remaining time.
Create a new deadline with the specified remaining time.
def initialize(remaining)
	@remaining = remaining
	@start = Clock.now
end

def remaining

@returns [Numeric] The remaining time (may be negative if expired).
the remaining time by the elapsed duration since the last call.
Each call to this method advances the internal clock and reduces
Get the remaining time, updating internal state.
def remaining
	now = Clock.now
	delta = now - @start
	@start = now
	
	@remaining -= delta
	
	return @remaining
end