Class: EsHttpClient::CaughtUpStream
- Inherits:
-
Object
- Object
- EsHttpClient::CaughtUpStream
- Defined in:
- lib/es_http_client/caught_up_stream.rb
Instance Method Summary collapse
- #fetch(ref, &block) ⇒ Object
-
#initialize(ref, connection) ⇒ CaughtUpStream
constructor
A new instance of CaughtUpStream.
- #subscribe(&block) ⇒ Object
Constructor Details
#initialize(ref, connection) ⇒ CaughtUpStream
Returns a new instance of CaughtUpStream.
8 9 10 11 |
# File 'lib/es_http_client/caught_up_stream.rb', line 8 def initialize(ref, connection) @ref = ref @connection = connection end |
Instance Method Details
#fetch(ref, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/es_http_client/caught_up_stream.rb', line 20 def fetch(ref, &block) response = @connection.get(ref.uri, ref.etag) page = Page.new(response.body) next_uri = ref.uri if page.has_entries? page.each_event(&block) next_uri = page.previous end return Ref.new(next_uri, response.headers['etag']) end |
#subscribe(&block) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/es_http_client/caught_up_stream.rb', line 13 def subscribe(&block) loop do sleep 1 @ref = fetch(@ref, &block) end end |