Class: ActiveRecord::FutureResult::EventBuffer

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/future_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(future_result, instrumenter) ⇒ EventBuffer

Returns a new instance of EventBuffer.



27
28
29
30
31
# File 'activerecord/lib/active_record/future_result.rb', line 27

def initialize(future_result, instrumenter)
  @future_result = future_result
  @instrumenter = instrumenter
  @events = []
end

Instance Method Details

#flushObject



39
40
41
42
43
44
45
# File 'activerecord/lib/active_record/future_result.rb', line 39

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
# File 'activerecord/lib/active_record/future_result.rb', line 33

def instrument(name, payload = {}, &block)
  event = @instrumenter.new_event(name, payload)
  @events << event
  event.record(&block)
end