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.



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

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

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

    # init the promise
    super(loop, defer)
end

Instance Attribute Details

#createdObject (readonly)

Returns the value of attribute created.



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

def created
  @created
end

#last_scheduledObject (readonly)

Returns the value of attribute last_scheduled.



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

def last_scheduled
  @last_scheduled
end

#next_scheduledObject (readonly)

Returns the value of attribute next_scheduled.



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

def next_scheduled
  @next_scheduled
end

#trigger_countObject (readonly)

Returns the value of attribute trigger_count.



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

def trigger_count
  @trigger_count
end

Instance Method Details

#<=>(anOther) ⇒ Object

required for comparable



42
43
44
# File 'lib/uv-rays/scheduler.rb', line 42

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

#cancelObject

reject the promise



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

def cancel
    @defer.reject(:cancelled)
end

#inspectObject Also known as: to_s

Provide relevant inspect information



30
31
32
33
34
35
36
37
# File 'lib/uv-rays/scheduler.rb', line 30

def inspect
    insp = "#<#{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



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

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