adjustable max for eventually

This commit is contained in:
Wesley Beary 2009-07-25 18:05:49 -07:00
parent 97dda626ba
commit cb6a1d85f8
1 changed files with 15 additions and 3 deletions

View File

@ -48,14 +48,26 @@ def eu_s3
end
end
def eventually(&block)
[0,2,4,8,16].each do |delay|
def eventually(max_delay = 16, &block)
delays = [0]
delay_step = 1
total = 0
while true
delay = 1
delay_step.times do
delay *= 2
end
delays << delay
delay_step += 1
break if delay >= max_delay
end
delays.each do |delay|
begin
sleep(delay)
yield
break
rescue => error
raise error if delay == 16
raise error if delay >= max_delay
end
end
end