Class: IO::Event::Timers::Handle

Inherits:
Object
  • Object
show all
Defined in:
lib/io/event/timers.rb

Overview

A handle to a scheduled timer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, block) ⇒ Handle

Initialize the handle with the given time and block.



20
21
22
23
24
# File 'lib/io/event/timers.rb', line 20

def initialize(time, block)
	@timers = nil
	@time = time
	@block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



30
31
32
# File 'lib/io/event/timers.rb', line 30

def block
  @block
end

#The block to call when the timer fires.(blocktocall) ⇒ Object (readonly)



30
# File 'lib/io/event/timers.rb', line 30

attr :block

#timeObject (readonly)

Returns the value of attribute time.



27
28
29
# File 'lib/io/event/timers.rb', line 27

def time
  @time
end

Instance Method Details

#<(other) ⇒ Object

Compare the handle with another handle.



46
47
48
# File 'lib/io/event/timers.rb', line 46

def < other
	@time < other.time
end

#>(other) ⇒ Object

Compare the handle with another handle.



54
55
56
# File 'lib/io/event/timers.rb', line 54

def > other
	@time > other.time
end

#callObject

Invoke the block.



59
60
61
# File 'lib/io/event/timers.rb', line 59

def call(...)
	@block.call(...)
end

#cancel!Object

Cancel the timer.



64
65
66
67
68
69
70
71
72
73
# File 'lib/io/event/timers.rb', line 64

def cancel!
	return if @block.nil?
	
	@block = nil
	
	if timers = @timers
		@timers = nil
		timers.cancelled!(self)
	end
end

#cancelled?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/io/event/timers.rb', line 76

def cancelled?
	@block.nil?
end

#removed!Object

Mark the timer as removed from the heap.



38
39
40
# File 'lib/io/event/timers.rb', line 38

def removed!
	@timers = nil
end

#schedule!(timers) ⇒ Object

Mark the timer as inserted into the heap.



33
34
35
# File 'lib/io/event/timers.rb', line 33

def schedule!(timers)
	@timers = timers
end

#The time at which the block should be called.=(timeatwhichtheblockshouldbecalled. = (value)) ⇒ Object



27
# File 'lib/io/event/timers.rb', line 27

attr :time