Module: Terminus::Timeouts

Includes:
Faye::Timeouts
Included in:
Browser, Controller
Defined in:
lib/terminus/timeouts.rb

Defined Under Namespace

Classes: TimeoutError

Constant Summary collapse

TIMEOUT =
30

Instance Method Summary collapse

Instance Method Details

#wait_with_timeout(name, duration = TIMEOUT, &predicate) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/terminus/timeouts.rb', line 10

def wait_with_timeout(name, duration = TIMEOUT, &predicate)
  result, time_out = predicate.call, false
  return result if result

  add_timeout(name, duration) { time_out = true }

  while !result and !time_out
    result = predicate.call
    sleep(0.001)
  end

  raise TimeoutError.new("Waited #{duration}s but could not get a #{name}") if time_out
  remove_timeout(name)

  result
end