Module: RSMP::Wait

Included in:
Node, Proxy
Defined in:
lib/rsmp/wait.rb

Instance Method Summary collapse

Instance Method Details

#wait_for(condition, timeout, &block) ⇒ Object

wait for an async condition to signal, then yield to block if block returns true we're done. otherwise, wait again

Raises:

  • (RuntimeError)

5
6
7
8
9
10
11
12
13
14
# File 'lib/rsmp/wait.rb', line 5

def wait_for condition, timeout, &block
  raise RuntimeError.new("Can't wait for condition because task is not running") unless @task.running?
  @task.with_timeout(timeout) do
    while @task.running? do
      value = condition.wait
      result = yield value 
      return result if result   # return result of check, if not nil
    end
  end
end