class Handle
A handle to a scheduled timer.
Definitions
def initialize(time, block)
Initialize the handle with the given time and block.
Signature
-
parameter
timeFloat The time at which the block should be called.
-
parameter
blockProc The block to call.
Implementation
def initialize(time, block)
@timers = nil
@time = time
@block = block
end
attr :time
Signature
-
attribute
Float The time at which the block should be called.
attr :block
Signature
-
attribute
Proc | Nil The block to call when the timer fires.
def schedule!(timers)
Mark the timer as inserted into the heap.
Implementation
def schedule!(timers)
@timers = timers
end
def removed!
Mark the timer as removed from the heap.
Implementation
def removed!
@timers = nil
end
def <(other)
Compare the handle with another handle.
Signature
-
parameter
otherHandle The other handle to compare with.
-
returns
Boolean Whether the handle is less than the other handle.
Implementation
def < other
@time < other.time
end
def >(other)
Compare the handle with another handle.
Signature
-
parameter
otherHandle The other handle to compare with.
-
returns
Boolean Whether the handle is greater than the other handle.
Implementation
def > other
@time > other.time
end
def call(...)
Invoke the block.
Implementation
def call(...)
@block.call(...)
end
def cancel!
Cancel the timer.
Implementation
def cancel!
return if @block.nil?
@block = nil
if timers = @timers
@timers = nil
timers.cancelled!(self)
end
end
def cancelled?
Signature
-
returns
Boolean Whether the timer has been cancelled.
Implementation
def cancelled?
@block.nil?
end