Class: UV::Repeat
- Inherits:
-
ScheduledEvent
- Object
- Libuv::Q::DeferredPromise
- ScheduledEvent
- UV::Repeat
- Defined in:
- lib/uv-rays/scheduler.rb
Instance Attribute Summary
Attributes inherited from ScheduledEvent
#created, #last_scheduled, #next_scheduled, #trigger_count
Instance Method Summary collapse
-
#initialize(scheduler, every) ⇒ Repeat
constructor
A new instance of Repeat.
-
#pause ⇒ Object
removes the event from the schedule.
-
#resume ⇒ Object
reschedules the event to the next time period can be used to reset a repeating timer.
-
#trigger ⇒ Object
Runs the event and reschedules.
-
#update(every) ⇒ Object
Update the time period of the repeating event.
Methods inherited from ScheduledEvent
Constructor Details
#initialize(scheduler, every) ⇒ Repeat
Returns a new instance of Repeat.
93 94 95 96 97 98 |
# File 'lib/uv-rays/scheduler.rb', line 93 def initialize(scheduler, every) super(scheduler) @every = every next_time end |
Instance Method Details
#pause ⇒ Object
removes the event from the schedule
112 113 114 115 |
# File 'lib/uv-rays/scheduler.rb', line 112 def pause @paused = true @scheduler.unschedule(self) end |
#resume ⇒ Object
reschedules the event to the next time period can be used to reset a repeating timer
119 120 121 122 123 |
# File 'lib/uv-rays/scheduler.rb', line 119 def resume @paused = false @last_scheduled = @reactor.now reschedule end |
#trigger ⇒ Object
Runs the event and reschedules
126 127 128 129 130 131 132 133 |
# File 'lib/uv-rays/scheduler.rb', line 126 def trigger super() @reactor.next_tick do # Do this next tick to avoid needless scheduling # if the event is stopped in the callback reschedule end end |
#update(every) ⇒ Object
Update the time period of the repeating event
103 104 105 106 107 108 109 |
# File 'lib/uv-rays/scheduler.rb', line 103 def update(every) time = Scheduler.parse_in(every, :quiet) || Scheduler.parse_cron(every, :quiet) raise ArgumentError.new("couldn't parse \"#{o}\"") if time.nil? @every = time reschedule end |