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.



74
75
76
77
78
79
80
# File 'lib/nexpose/wait.rb', line 74

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.



72
73
74
# File 'lib/nexpose/wait.rb', line 72

def poll_begin
  @poll_begin
end

#polling_intervalObject (readonly)

Stand alone object to handle waiting logic.



72
73
74
# File 'lib/nexpose/wait.rb', line 72

def polling_interval
  @polling_interval
end

#timeoutObject (readonly)

Stand alone object to handle waiting logic.



72
73
74
# File 'lib/nexpose/wait.rb', line 72

def timeout
  @timeout
end

Instance Method Details

#wait(condition) ⇒ Object



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

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