Class: Cumuli::Waiter

Inherits:
Object
  • Object
show all
Defined in:
lib/cumuli/waiter.rb

Constant Summary collapse

TIMEOUT =
30
MESSAGE =
"#wait_until did not resolve after #{TIMEOUT} seconds"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = MESSAGE) ⇒ Waiter

Returns a new instance of Waiter.



8
9
10
# File 'lib/cumuli/waiter.rb', line 8

def initialize(message=MESSAGE)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/cumuli/waiter.rb', line 6

def message
  @message
end

Instance Method Details

#wait_until(timeout = TIMEOUT, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/cumuli/waiter.rb', line 12

def wait_until(timeout=TIMEOUT, &block)
  begin
    Timeout.timeout(timeout) do
      sleep(0.1) until value = block.call
      value
    end
  rescue Timeout::Error
    raise message
  end
end