Class: Togul::StreamClient
- Inherits:
-
Object
- Object
- Togul::StreamClient
- Defined in:
- lib/togul/stream_client.rb
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(config, cache) ⇒ StreamClient
constructor
A new instance of StreamClient.
- #on_cache_invalidated(&block) ⇒ Object
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
#connect ⇒ Object
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 |