Class: UV::OneShot
- Inherits:
-
ScheduledEvent
- Object
- Libuv::Q::DeferredPromise
- ScheduledEvent
- UV::OneShot
- 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, at) ⇒ OneShot
constructor
A new instance of OneShot.
-
#trigger ⇒ Object
Runs the event and cancels the schedule.
-
#update(time) ⇒ Object
Updates the scheduled time.
Methods inherited from ScheduledEvent
Constructor Details
#initialize(scheduler, at) ⇒ OneShot
Returns a new instance of OneShot.
59 60 61 62 63 |
# File 'lib/uv-rays/scheduler.rb', line 59 def initialize(scheduler, at) super(scheduler) @next_scheduled = at end |
Instance Method Details
#trigger ⇒ Object
Runs the event and cancels the schedule
82 83 84 85 |
# File 'lib/uv-rays/scheduler.rb', line 82 def trigger super() @defer.resolve(:triggered) end |
#update(time) ⇒ Object
Updates the scheduled time
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/uv-rays/scheduler.rb', line 66 def update(time) @last_scheduled = @loop.now parsed_time = Scheduler.parse_in(time, :quiet) if parsed_time.nil? # Parse at will throw an error if time is invalid parsed_time = Scheduler.parse_at(time) - @scheduler.time_diff else parsed_time += @last_scheduled end @next_scheduled = parsed_time @scheduler.reschedule(self) end |