Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#try_for(seconds) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/try-for.rb', line 1

def try_for(seconds)
  time = Time.now.to_i
  success = false

  while !success and Time.now.to_i - time < seconds do
    begin
      yield
      success = true
    rescue Exception
      sleep 0.1
    end
  end

  yield unless success
end