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.
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
#created ⇒ Object (readonly)
Returns the value of attribute created.
10 11 12 |
# File 'lib/uv-rays/scheduler.rb', line 10 def created @created end |
#last_scheduled ⇒ Object (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_scheduled ⇒ Object (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_count ⇒ Object (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 |
#cancel ⇒ Object
reject the promise
51 52 53 |
# File 'lib/uv-rays/scheduler.rb', line 51 def cancel @defer.reject(:cancelled) end |
#inspect ⇒ Object 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 |
#trigger ⇒ Object
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 |