Class: LibvirtAsync::Timer::Monitor
- Inherits:
-
Object
- Object
- LibvirtAsync::Timer::Monitor
- Defined in:
- lib/libvirt_async/timer.rb
Overview
Represents a When a timer expires, we dispatch the event to libvirt via Libvirt::Event.invoke_timeout_callback (feeding it the timer_id we returned from add_timer and the opaque data that libvirt gave us earlier).
Defined Under Namespace
Classes: Cancelled
Instance Attribute Summary collapse
-
#fiber ⇒ Object
readonly
Returns the value of attribute fiber.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ Monitor
constructor
A new instance of Monitor.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #wait(timeout) ⇒ Object
Constructor Details
#initialize ⇒ Monitor
Returns a new instance of Monitor.
19 20 21 |
# File 'lib/libvirt_async/timer.rb', line 19 def initialize @fiber = nil end |
Instance Attribute Details
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
17 18 19 |
# File 'lib/libvirt_async/timer.rb', line 17 def fiber @fiber end |
Instance Method Details
#close ⇒ Object
29 30 31 32 |
# File 'lib/libvirt_async/timer.rb', line 29 def close @fiber.resume(Cancelled.new) if @fiber&.alive? @fiber = nil end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/libvirt_async/timer.rb', line 38 def inspect to_s end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/libvirt_async/timer.rb', line 34 def to_s "#<#{self.class}:0x#{object_id.to_s(16)} fiber=#{@fiber.&object_id&.to_s(16)} alive=#{@fiber&.alive?}>" end |
#wait(timeout) ⇒ Object
23 24 25 26 27 |
# File 'lib/libvirt_async/timer.rb', line 23 def wait(timeout) @fiber = Async::Task.current.fiber Async::Task.current.sleep(timeout) @fiber = nil end |