Class: ActiveRecord::FutureResult::EventBuffer
- Inherits:
-
Object
- Object
- ActiveRecord::FutureResult::EventBuffer
- Defined in:
- lib/active_record/future_result.rb
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(future_result, instrumenter) ⇒ EventBuffer
constructor
A new instance of EventBuffer.
- #instrument(name, payload = {}, &block) ⇒ Object
Constructor Details
#initialize(future_result, instrumenter) ⇒ EventBuffer
Returns a new instance of EventBuffer.
27 28 29 30 31 |
# File 'lib/active_record/future_result.rb', line 27 def initialize(future_result, instrumenter) @future_result = future_result @instrumenter = instrumenter @events = [] end |
Instance Method Details
#flush ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/active_record/future_result.rb', line 42 def flush events, @events = @events, [] events.each do |event| event.payload[:lock_wait] = @future_result.lock_wait ActiveSupport::Notifications.publish_event(event) end end |
#instrument(name, payload = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/active_record/future_result.rb', line 33 def instrument(name, payload = {}, &block) event = @instrumenter.new_event(name, payload) begin event.record(&block) ensure @events << event end end |