H
Hal Fulton
I sometimes find myself retrying operations when in a networked
situation (e.g., maybe server isn't up, just try again).
I just wrote this little bit of code.
Tell me what you think... I'm sure it can be improved.
Cheers,
Hal
def try(quiet=true,times=5,secs=1,&block)
count = 0
catch :finished do
begin
block.call
rescue => err
puts "Error was: #{err}" if not quiet
count += 1
throw :finished if count > times
sleep secs
retry
end
end
end
situation (e.g., maybe server isn't up, just try again).
I just wrote this little bit of code.
Tell me what you think... I'm sure it can be improved.
Cheers,
Hal
def try(quiet=true,times=5,secs=1,&block)
count = 0
catch :finished do
begin
block.call
rescue => err
puts "Error was: #{err}" if not quiet
count += 1
throw :finished if count > times
sleep secs
retry
end
end
end