Sha256: 5f226289270f9cc6634459ee9d2f80570f91f9fda515c21d8e13b6e494f1aba0
Contents?: true
Size: 728 Bytes
Versions: 1
Compression:
Stored size: 728 Bytes
Contents
module Spruz module Attempt def attempt(attempts = 1, exception_class = StandardError, sleep_duration = nil, &block) return if attempts <= 0 count = 0 if exception_class.nil? begin count += 1 if block.call(count) return true elsif sleep_duration and count < attempts sleep sleep_duration end end until count == attempts false else begin count += 1 block.call(count) true rescue exception_class if count < attempts sleep_duration and sleep sleep_duration retry end false end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spruz-0.2.5 | lib/spruz/attempt.rb |