Class: EM::Synchrony::ActiveRecord::ConnectionPool

Inherits:
ConnectionPool
  • Object
show all
Defined in:
lib/em-synchrony/activerecord.rb

Instance Method Summary collapse

Instance Method Details

#acquire(fiber) ⇒ Object


127
128
129
130
# File 'lib/em-synchrony/activerecord.rb', line 127

def acquire(fiber)
  return @reserved[fiber.object_id] if @reserved[fiber.object_id]
  super
end

#affected_rows(*args, &blk) ⇒ Object

via method_missing affected_rows will be recognized as async method


137
138
139
140
141
# File 'lib/em-synchrony/activerecord.rb', line 137

def affected_rows(*args, &blk)
  execute(false) do |conn|
    conn.send(:affected_rows, *args, &blk)
  end
end

#connectionObject


132
133
134
# File 'lib/em-synchrony/activerecord.rb', line 132

def connection
  acquire(Fiber.current)
end

#execute(async) ⇒ Object

consider connection acquired


115
116
117
118
119
120
121
122
123
124
125
# File 'lib/em-synchrony/activerecord.rb', line 115

def execute(async)
  f = Fiber.current
  begin
    conn = acquire(f)
    conn.acquired_for_connection_pool += 1
    yield conn
  ensure
    conn.acquired_for_connection_pool -= 1
    release(f) if !async && conn.acquired_for_connection_pool == 0
  end
end