Class: Evinrude::Backoff

Inherits:
Object
  • Object
show all
Defined in:
lib/evinrude/backoff.rb

Instance Method Summary collapse

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

#waitObject



15
16
17
# File 'lib/evinrude/backoff.rb', line 15

def wait
  sleep wait_time
end

#wait_timeObject



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