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.



17
18
19
# File 'lib/libvirt_async/timer.rb', line 17

def initialize
  @fiber = nil
end

Instance Attribute Details

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

#closeObject



27
28
29
30
# File 'lib/libvirt_async/timer.rb', line 27

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

#inspectObject



36
37
38
# File 'lib/libvirt_async/timer.rb', line 36

def inspect
  to_s
end

#to_sObject



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