Class: Packet::PeriodicEvent
- Inherits:
-
Object
- Object
- Packet::PeriodicEvent
- Defined in:
- lib/packet/packet_periodic_event.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#cancel_flag ⇒ Object
Returns the value of attribute cancel_flag.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#timer_signature ⇒ Object
Returns the value of attribute timer_signature.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(interval, &block) ⇒ PeriodicEvent
constructor
A new instance of PeriodicEvent.
- #run ⇒ Object
- #run_now? ⇒ Boolean
Constructor Details
#initialize(interval, &block) ⇒ PeriodicEvent
Returns a new instance of PeriodicEvent.
4 5 6 7 8 9 10 |
# File 'lib/packet/packet_periodic_event.rb', line 4 def initialize(interval, &block) @cancel_flag = false @timer_signature = Guid.hexdigest @block = block @scheduled_time = Time.now + interval @interval = interval end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/packet/packet_periodic_event.rb', line 3 def block @block end |
#cancel_flag ⇒ Object
Returns the value of attribute cancel_flag.
3 4 5 |
# File 'lib/packet/packet_periodic_event.rb', line 3 def cancel_flag @cancel_flag end |
#interval ⇒ Object
Returns the value of attribute interval.
3 4 5 |
# File 'lib/packet/packet_periodic_event.rb', line 3 def interval @interval end |
#timer_signature ⇒ Object
Returns the value of attribute timer_signature.
3 4 5 |
# File 'lib/packet/packet_periodic_event.rb', line 3 def timer_signature @timer_signature end |
Instance Method Details
#cancel ⇒ Object
17 18 19 |
# File 'lib/packet/packet_periodic_event.rb', line 17 def cancel @cancel_flag = true end |
#run ⇒ Object
21 22 23 24 |
# File 'lib/packet/packet_periodic_event.rb', line 21 def run @scheduled_time += @interval @block.call end |
#run_now? ⇒ Boolean
12 13 14 15 |
# File 'lib/packet/packet_periodic_event.rb', line 12 def run_now? return true if @scheduled_time <= Time.now return false end |