Class: InstantRecord::EventsController::EventStream
- Inherits:
-
Object
- Object
- InstantRecord::EventsController::EventStream
- Defined in:
- app/controllers/instant_record/events_controller.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(cursor:, deadline:) ⇒ EventStream
constructor
A new instance of EventStream.
Constructor Details
#initialize(cursor:, deadline:) ⇒ EventStream
Returns a new instance of EventStream.
22 23 24 25 |
# File 'app/controllers/instant_record/events_controller.rb', line 22 def initialize(cursor:, deadline:) @cursor = cursor @deadline = deadline end |
Instance Method Details
#each ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/instant_record/events_controller.rb', line 27 def each loop do Change.poll(@cursor).each do |change| @cursor = change.id yield "id: #{change.id}\nevent: change\ndata: #{change.as_event.to_json}\n\n" end break if Time.current >= @deadline sleep 0.5 end end |