Module: Tobacco::Burnout
- Defined in:
- lib/tobacco/burnout.rb
Defined Under Namespace
Classes: MaximumAttemptsExceeded
Class Method Summary
collapse
Class Method Details
.attempt(&block) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/tobacco/burnout.rb', line 19
def self.attempt(&block)
begin
[ true, yield ]
rescue
false
end
end
|
.try(max_attempts, &block) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/tobacco/burnout.rb', line 6
def self.try(max_attempts, &block)
attempts = 1
while(attempts <= max_attempts)
success, return_value = attempt &block
return return_value if success
attempts += 1
end
raise MaximumAttemptsExceeded.new("Execution timed out more than #{max_attempts} time(s). I give up.")
end
|