Class: Nexpose::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/wait.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout: nil, polling_interval: nil) ⇒ Poller

Returns a new instance of Poller.



80
81
82
83
84
85
86
# File 'lib/nexpose/wait.rb', line 80

def initialize(timeout: nil, polling_interval: nil)
  global_timeout = set_global_timeout
  @timeout = timeout.nil? ? global_timeout : timeout

  global_polling = set_polling_interval
  @polling_interval = polling_interval.nil? ? global_polling : polling_interval
end

Instance Attribute Details

#poll_beginObject (readonly)

Stand alone object to handle waiting logic.



78
79
80
# File 'lib/nexpose/wait.rb', line 78

def poll_begin
  @poll_begin
end

#polling_intervalObject (readonly)

Stand alone object to handle waiting logic.



78
79
80
# File 'lib/nexpose/wait.rb', line 78

def polling_interval
  @polling_interval
end

#timeoutObject (readonly)

Stand alone object to handle waiting logic.



78
79
80
# File 'lib/nexpose/wait.rb', line 78

def timeout
  @timeout
end

Instance Method Details

#wait(condition) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/nexpose/wait.rb', line 88

def wait(condition)
  @poll_begin = Time.now
  loop do
    break if condition.call
    raise TimeoutError if @poll_begin + @timeout < Time.now
    sleep @polling_interval
  end
end