Class: SplitIoClient::SSE::EventSource::BackOff

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/sse/event_source/back_off.rb

Instance Method Summary collapse

Constructor Details

#initialize(back_off_base, attempt = 0) ⇒ BackOff

Returns a new instance of BackOff.



7
8
9
10
# File 'lib/splitclient-rb/sse/event_source/back_off.rb', line 7

def initialize(back_off_base, attempt = 0)
  @attempt = attempt
  @back_off_base = back_off_base
end

Instance Method Details

#intervalObject



12
13
14
15
16
17
# File 'lib/splitclient-rb/sse/event_source/back_off.rb', line 12

def interval
  interval = (@back_off_base * (2**@attempt)) if @attempt.positive?
  @attempt += 1

  interval || 0
end

#resetObject



19
20
21
# File 'lib/splitclient-rb/sse/event_source/back_off.rb', line 19

def reset
  @attempt = 0
end