Class: UV::OneShot

Inherits:
ScheduledEvent show all
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

Methods inherited from ScheduledEvent

#<=>, #cancel, #inspect, #to_time

Constructor Details

#initialize(scheduler, at) ⇒ OneShot

Returns a new instance of OneShot.



74
75
76
77
78
# File 'lib/uv-rays/scheduler.rb', line 74

def initialize(scheduler, at)
    super(scheduler)

    @next_scheduled = at
end

Instance Method Details

#triggerObject

Runs the event and cancels the schedule



97
98
99
100
# File 'lib/uv-rays/scheduler.rb', line 97

def trigger
    super()
    @defer.resolve(:triggered)
end

#update(time) ⇒ Object

Updates the scheduled time



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/uv-rays/scheduler.rb', line 81

def update(time)
    @last_scheduled = @reactor.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