Class: VirtualBox::COM::Interface::Version_3_2_X::Progress

Inherits:
AbstractInterface show all
Defined in:
lib/virtualbox/com/interface/3.2.x/progress.rb

Constant Summary collapse

IID =
"856aa038-853f-42e2-acf7-6e7b02dbe294"

Instance Attribute Summary

Attributes inherited from AbstractInterface

#implementer, #lib

Instance Method Summary collapse

Methods inherited from AbstractInterface

#call_function, function, functions, #has_function?, #has_property?, #initialize, #inspect, #member, member, members, #members, properties, property, #read_property, #write_property

Constructor Details

This class inherits a constructor from VirtualBox::COM::AbstractInterface

Instance Method Details

#wait(interval_percent = 1) ⇒ Object

This method blocks the execution while the operations represented by this VirtualBox::COM::Interface::Version_3_2_X::Progress object execute, but yields a block every ‘x` percent (interval given in parameters).



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/virtualbox/com/interface/3.2.x/progress.rb', line 33

def wait(interval_percent=1)
  # If no block is given we just wait until completion, not worrying
  # about tracking percentages.
  if !block_given?
    wait_for_completion(-1)
    return
  end

  # Initial value forces the 0% yield
  last_reported = -100

  while true
    delta = percent - last_reported
    last_reported += delta
    yield self if delta >= interval_percent

    # This either sleeps for half a second or returns on
    # completion
    wait_for_completion(500)

    break if completed || canceled

    # Pass off execution so other threads can run
    Thread.pass
  end
end