Class: SplitIoClient::SSE::EventSource::BackOff
- Inherits:
-
Object
- Object
- SplitIoClient::SSE::EventSource::BackOff
- Defined in:
- lib/splitclient-rb/sse/event_source/back_off.rb
Instance Method Summary collapse
-
#initialize(back_off_base, attempt = 0) ⇒ BackOff
constructor
A new instance of BackOff.
- #interval ⇒ Object
- #reset ⇒ Object
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
#interval ⇒ Object
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 |
#reset ⇒ Object
19 20 21 |
# File 'lib/splitclient-rb/sse/event_source/back_off.rb', line 19 def reset @attempt = 0 end |