Class: ActiveRecord::FutureResult::EventBuffer

Inherits:
Object
  • Object
show all
Defined in:
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 '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



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