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



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

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.



7
8
9
# File 'lib/uv-rays/scheduler.rb', line 7

def created
  @created
end

#last_scheduledObject (readonly)

Returns the value of attribute last_scheduled.



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

def last_scheduled
  @last_scheduled
end

#next_scheduledObject (readonly)

Returns the value of attribute next_scheduled.



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

def next_scheduled
  @next_scheduled
end

#trigger_countObject (readonly)

Returns the value of attribute trigger_count.



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

def trigger_count
  @trigger_count
end

Instance Method Details

#<=>(anOther) ⇒ Object

required for comparable



28
29
30
# File 'lib/uv-rays/scheduler.rb', line 28

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

#cancelObject

reject the promise



33
34
35
# File 'lib/uv-rays/scheduler.rb', line 33

def cancel
    @defer.reject(:cancelled)
end

#triggerObject

notify listeners of the event



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

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