Method: Eye::Process::System#wait_for_condition

Defined in:
lib/eye/process/system.rb

#wait_for_condition(timeout, step = 0.1, &_block) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/eye/process/system.rb', line 77

def wait_for_condition(timeout, step = 0.1, &_block)
  res = nil
  sumtime = 0

  loop do
    tm = Time.now
    res = yield # note that yield can block actor here and timeout can be overhead
    return res if res
    sleep step.to_f
    sumtime += (Time.now - tm)
    return false if sumtime > timeout
  end
end