Class: PeriodicScheduler::Event
- Inherits:
-
Object
- Object
- PeriodicScheduler::Event
- Defined in:
- lib/periodic-scheduler.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#keep ⇒ Object
readonly
Returns the value of attribute keep.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#quantum_period ⇒ Object
readonly
Returns the value of attribute quantum_period.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(quantized_space, now, period, keep, &callback) ⇒ Event
constructor
A new instance of Event.
- #keep? ⇒ Boolean
- #reschedule(qnow) ⇒ Object
- #reschedule_hook(&callback) ⇒ Object
- #stop ⇒ Object
- #stop_hook(&callback) ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(quantized_space, now, period, keep, &callback) ⇒ Event
Returns a new instance of Event.
30 31 32 33 34 35 36 37 |
# File 'lib/periodic-scheduler.rb', line 30 def initialize(quantized_space, now, period, keep, &callback) @quantized_space = quantized_space @period = period @run_time = now + period @keep = keep @callback = callback quantatize(@run_time) end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
28 29 30 |
# File 'lib/periodic-scheduler.rb', line 28 def callback @callback end |
#keep ⇒ Object (readonly)
Returns the value of attribute keep.
27 28 29 |
# File 'lib/periodic-scheduler.rb', line 27 def keep @keep end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
26 27 28 |
# File 'lib/periodic-scheduler.rb', line 26 def period @period end |
#quantum_period ⇒ Object (readonly)
Returns the value of attribute quantum_period.
25 26 27 |
# File 'lib/periodic-scheduler.rb', line 25 def quantum_period @quantum_period end |
Instance Method Details
#call ⇒ Object
71 72 73 |
# File 'lib/periodic-scheduler.rb', line 71 def call @callback.call end |
#keep? ⇒ Boolean
53 54 55 |
# File 'lib/periodic-scheduler.rb', line 53 def keep? @keep end |
#reschedule(qnow) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/periodic-scheduler.rb', line 39 def reschedule(qnow) # keep rescheduling until we get it scheduled in future quant until @quantum_period > qnow @run_time += @period quantatize(@run_time) end @reschedule_hook.call(self) if @reschedule_hook end |
#reschedule_hook(&callback) ⇒ Object
49 50 51 |
# File 'lib/periodic-scheduler.rb', line 49 def reschedule_hook(&callback) @reschedule_hook = callback end |
#stop ⇒ Object
57 58 59 60 61 |
# File 'lib/periodic-scheduler.rb', line 57 def stop return if @stopped @stopped = true @stop_hook.call(self) if @reschedule_hook end |
#stop_hook(&callback) ⇒ Object
67 68 69 |
# File 'lib/periodic-scheduler.rb', line 67 def stop_hook(&callback) @stop_hook = callback end |
#stopped? ⇒ Boolean
63 64 65 |
# File 'lib/periodic-scheduler.rb', line 63 def stopped? @stopped end |