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

Constructor Details

#initialize(scheduler, at) ⇒ OneShot



45
46
47
48
49
# File 'lib/uv-rays/scheduler.rb', line 45

def initialize(scheduler, at)
    super(scheduler)

    @next_scheduled = at
end

Instance Method Details

#triggerObject

Runs the event and cancels the schedule



69
70
71
72
# File 'lib/uv-rays/scheduler.rb', line 69

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

#update(time) ⇒ Object

Updates the scheduled time



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/uv-rays/scheduler.rb', line 52

def update(time)
    @last_scheduled = @loop.now

    
    parsed_time = parse_in(time, :quiet)
    if parsed_time.nil?
        # Parse at will throw an error if time is invalid

        parsed_time = parse_at(time) - @scheduler.time_diff
    else
        parsed_time += @last_scheduled
    end

    @next_scheduled = parsed_time
    @scheduler.reschedule(self)
end