Class: UV::ScheduledEvent

Inherits:
Libuv::Q::DeferredPromise
  • Object
show all
Includes:
Comparable
Defined in:
lib/uv-rays/scheduler.rb

Direct Known Subclasses

OneShot, Repeat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheduler) ⇒ ScheduledEvent

Returns a new instance of ScheduledEvent.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/uv-rays/scheduler.rb', line 15

def initialize(scheduler)
    # Create a dummy deferrable
    reactor = scheduler.reactor
    defer = reactor.defer

    # Record a backtrace of where the schedule was created
    @trace = caller

    # Setup common event variables
    @scheduler = scheduler
    @created = reactor.now
    @last_scheduled = @created
    @trigger_count = 0

    # init the promise
    super(reactor, defer)
end

Instance Attribute Details

#createdObject (readonly)

Returns the value of attribute created.



10
11
12
# File 'lib/uv-rays/scheduler.rb', line 10

def created
  @created
end

#last_scheduledObject (readonly)

Returns the value of attribute last_scheduled.



11
12
13
# File 'lib/uv-rays/scheduler.rb', line 11

def last_scheduled
  @last_scheduled
end

#next_scheduledObject (readonly)

Returns the value of attribute next_scheduled.



12
13
14
# File 'lib/uv-rays/scheduler.rb', line 12

def next_scheduled
  @next_scheduled
end

#trigger_countObject (readonly)

Returns the value of attribute trigger_count.



13
14
15
# File 'lib/uv-rays/scheduler.rb', line 13

def trigger_count
  @trigger_count
end

Instance Method Details

#<=>(anOther) ⇒ Object

required for comparable



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

def <=>(anOther)
    @next_scheduled <=> anOther.next_scheduled
end

#cancelObject

reject the promise



51
52
53
# File 'lib/uv-rays/scheduler.rb', line 51

def cancel
    @defer.reject(:cancelled)
end

#inspectObject Also known as: to_s

Provide relevant inspect information



34
35
36
37
38
39
40
41
# File 'lib/uv-rays/scheduler.rb', line 34

def inspect
    insp = String.new("#<#{self.class}:0x#{self.__id__.to_s(16)} ")
    insp << "trigger_count=#{@trigger_count} "
    insp << "config=#{info} " if self.respond_to?(:info, true)
    insp << "next_scheduled=#{@next_scheduled} "
    insp << "last_scheduled=#{@last_scheduled} created=#{@created}>"
    insp
end

#triggerObject

notify listeners of the event



56
57
58
59
# File 'lib/uv-rays/scheduler.rb', line 56

def trigger
    @trigger_count += 1
    @defer.notify(@reactor.now, self)
end