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)
@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?
Check if the deadline has expired.
def expired? self.remaining <= 0 end
def initialize(remaining)
Create a new deadline with the specified remaining time.
def initialize(remaining) @remaining = remaining @start = Clock.now end
def remaining
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