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.



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

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.



80
81
82
# File 'lib/nexpose/wait.rb', line 80

def poll_begin
  @poll_begin
end

#polling_intervalObject (readonly)

Stand alone object to handle waiting logic.



80
81
82
# File 'lib/nexpose/wait.rb', line 80

def polling_interval
  @polling_interval
end

#timeoutObject (readonly)

Stand alone object to handle waiting logic.



80
81
82
# File 'lib/nexpose/wait.rb', line 80

def timeout
  @timeout
end

Instance Method Details

#wait(condition) ⇒ Object



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

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