Class: LibvirtAsync::Timer::Monitor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeMonitor

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

#fiberObject (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

#closeObject



29
30
31
32
# File 'lib/libvirt_async/timer.rb', line 29

def close
  @fiber.resume(Cancelled.new) if @fiber&.alive?
  @fiber = nil
end

#inspectObject



38
39
40
# File 'lib/libvirt_async/timer.rb', line 38

def inspect
  to_s
end

#to_sObject



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