Class: Waiting::Waiter
- Inherits:
-
Object
- Object
- Waiting::Waiter
- Defined in:
- lib/waiting/waiter.rb
Overview
The class that patiently waits
Instance Attribute Summary collapse
-
#attempts ⇒ Integer
readonly
The current attempt number.
-
#exp_base ⇒ Numeric
The exp base.
-
#interval ⇒ Numeric
The interval.
-
#max_attempts ⇒ Numeric
The max attempts.
-
#max_interval ⇒ Numeric
The max interval.
Instance Method Summary collapse
-
#done ⇒ Object
Mark the waiter as done.
-
#done? ⇒ Boolean
Is the waiter done?.
-
#initialize(exp_base: Waiting.default_exp_base, interval: Waiting.interval, max_attempts: Waiting.max_attempts, max_interval: Waiting.max_interval) {|waiter| ... } ⇒ Waiter
constructor
A new instance of Waiter.
-
#wait ⇒ Object
Waits for
#doneto be called.
Constructor Details
#initialize(exp_base: Waiting.default_exp_base, interval: Waiting.interval, max_attempts: Waiting.max_attempts, max_interval: Waiting.max_interval) {|waiter| ... } ⇒ Waiter
Returns a new instance of Waiter.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/waiting/waiter.rb', line 45 def initialize(exp_base: Waiting.default_exp_base, interval: Waiting.interval, max_attempts: Waiting.max_attempts, max_interval: Waiting.max_interval) @exp_base = exp_base @interval = interval @max_attempts = max_attempts @max_interval = max_interval @done = false @attempts = 0 end |
Instance Attribute Details
#attempts ⇒ Integer (readonly)
The current attempt number
11 12 13 |
# File 'lib/waiting/waiter.rb', line 11 def attempts @attempts end |
#exp_base ⇒ Numeric
The exp base
17 18 19 |
# File 'lib/waiting/waiter.rb', line 17 def exp_base @exp_base end |
#interval ⇒ Numeric
The interval
23 24 25 |
# File 'lib/waiting/waiter.rb', line 23 def interval @interval end |
#max_attempts ⇒ Numeric
The max attempts
29 30 31 |
# File 'lib/waiting/waiter.rb', line 29 def max_attempts @max_attempts end |
#max_interval ⇒ Numeric
The max interval
35 36 37 |
# File 'lib/waiting/waiter.rb', line 35 def max_interval @max_interval end |
Instance Method Details
#done ⇒ Object
Mark the waiter as done
61 62 63 |
# File 'lib/waiting/waiter.rb', line 61 def done @done = true end |
#done? ⇒ Boolean
Is the waiter done?
69 70 71 |
# File 'lib/waiting/waiter.rb', line 69 def done? @done end |
#wait ⇒ Object
Waits for #done to be called
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/waiting/waiter.rb', line 77 def wait loop do if @attempts >= max_attempts raise Waiting::TimedOutError, "Timed out after #{interval * max_attempts}s" end yield(self) break if done? wait_once end end |