Class: UV::ScheduledEvent
- Inherits:
-
Libuv::Q::DeferredPromise
- Object
- Libuv::Q::DeferredPromise
- UV::ScheduledEvent
- Includes:
- Comparable
- Defined in:
- lib/uv-rays/scheduler.rb
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#last_scheduled ⇒ Object
readonly
Returns the value of attribute last_scheduled.
-
#next_scheduled ⇒ Object
readonly
Returns the value of attribute next_scheduled.
-
#trigger_count ⇒ Object
readonly
Returns the value of attribute trigger_count.
Instance Method Summary collapse
-
#<=>(anOther) ⇒ Object
required for comparable.
-
#cancel ⇒ Object
reject the promise.
-
#initialize(scheduler) ⇒ ScheduledEvent
constructor
A new instance of ScheduledEvent.
-
#inspect ⇒ Object
(also: #to_s)
Provide relevant inspect information.
-
#trigger ⇒ Object
notify listeners of the event.
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
#created ⇒ Object (readonly)
Returns the value of attribute created.
9 10 11 |
# File 'lib/uv-rays/scheduler.rb', line 9 def created @created end |
#last_scheduled ⇒ Object (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_scheduled ⇒ Object (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_count ⇒ Object (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 |
#cancel ⇒ Object
reject the promise
47 48 49 |
# File 'lib/uv-rays/scheduler.rb', line 47 def cancel @defer.reject(:cancelled) end |
#inspect ⇒ Object 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 |
#trigger ⇒ Object
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 |