Class: Evinrude::Backoff
- Inherits:
-
Object
- Object
- Evinrude::Backoff
- Defined in:
- lib/evinrude/backoff.rb
Instance Method Summary collapse
-
#initialize(slot_time: 0.5, max_slots: 30) ⇒ Backoff
constructor
A new instance of Backoff.
- #wait ⇒ Object
- #wait_time ⇒ Object
Constructor Details
#initialize(slot_time: 0.5, max_slots: 30) ⇒ Backoff
Returns a new instance of Backoff.
3 4 5 6 7 |
# File 'lib/evinrude/backoff.rb', line 3 def initialize(slot_time: 0.5, max_slots: 30) @slot_time, @max_slots = slot_time, max_slots @fail_count = 0 end |
Instance Method Details
#wait ⇒ Object
15 16 17 |
# File 'lib/evinrude/backoff.rb', line 15 def wait sleep wait_time end |
#wait_time ⇒ Object
9 10 11 12 13 |
# File 'lib/evinrude/backoff.rb', line 9 def wait_time @fail_count += 1 [2 ** @fail_count, @max_slots].min * rand * @slot_time end |