Class: Togul::StreamClient

Inherits:
Object
  • Object
show all
Defined in:
lib/togul/stream_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, cache) ⇒ StreamClient

Returns a new instance of StreamClient.



9
10
11
12
13
# File 'lib/togul/stream_client.rb', line 9

def initialize(config, cache)
  @config = config
  @cache = cache
  @listeners = []
end

Instance Method Details

#connectObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/togul/stream_client.rb', line 15

def connect
  backoff = 1

  loop do
    stream_once
  rescue Error => e
    raise if [401, 403].include?(e.status_code)

    sleep(backoff)
    backoff = [backoff * 2, 30].min
  end
end

#on_cache_invalidated(&block) ⇒ Object



28
29
30
# File 'lib/togul/stream_client.rb', line 28

def on_cache_invalidated(&block)
  @listeners << block
end