Class: EsReadModel::Stream
- Inherits:
-
Object
- Object
- EsReadModel::Stream
- Defined in:
- lib/es_readmodel/stream.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each_event(&blk) ⇒ Object
-
#initialize(head_uri, connection, listener) ⇒ Stream
constructor
A new instance of Stream.
- #wait_for_new_events ⇒ Object
Constructor Details
#initialize(head_uri, connection, listener) ⇒ Stream
Returns a new instance of Stream.
11 12 13 14 15 16 |
# File 'lib/es_readmodel/stream.rb', line 11 def initialize(head_uri, connection, listener) @connection = connection @listener = listener @current_etag = nil fetch_first_page(head_uri) end |
Class Method Details
.open(name, connection, listener) ⇒ Object
7 8 9 |
# File 'lib/es_readmodel/stream.rb', line 7 def Stream.open(name, connection, listener) Stream.new("/streams/#{name}", connection, listener) end |
Instance Method Details
#each_event(&blk) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/es_readmodel/stream.rb', line 25 def each_event(&blk) while !@current_page.empty? @current_page.each_event(&blk) fetch(@current_page.newer_events_uri) if @current_page.newer_events_uri end end |
#wait_for_new_events ⇒ Object
18 19 20 21 22 23 |
# File 'lib/es_readmodel/stream.rb', line 18 def wait_for_new_events while @current_page.empty? sleep 1 fetch(@current_uri) end end |