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

Constructor Details

#initialize(scheduler, at) ⇒ OneShot

Returns a new instance of OneShot.



63
64
65
66
67
# File 'lib/uv-rays/scheduler.rb', line 63

def initialize(scheduler, at)
    super(scheduler)

    @next_scheduled = at
end

Instance Method Details

#triggerObject

Runs the event and cancels the schedule



86
87
88
89
# File 'lib/uv-rays/scheduler.rb', line 86

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

#update(time) ⇒ Object

Updates the scheduled time



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/uv-rays/scheduler.rb', line 70

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