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.
17 18 19 |
# File 'lib/libvirt_async/timer.rb', line 17 def initialize @fiber = nil end |
Instance Attribute Details
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
15 16 17 |
# File 'lib/libvirt_async/timer.rb', line 15 def fiber @fiber end |
Instance Method Details
#close ⇒ Object
27 28 29 30 |
# File 'lib/libvirt_async/timer.rb', line 27 def close @fiber.resume(Cancelled.new) if @fiber&.alive? @fiber = nil end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/libvirt_async/timer.rb', line 36 def inspect to_s end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/libvirt_async/timer.rb', line 32 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
21 22 23 24 25 |
# File 'lib/libvirt_async/timer.rb', line 21 def wait(timeout) @fiber = Async::Task.current.fiber Async::Task.current.sleep(timeout) @fiber = nil end |