Class: ActiveRecord::ConnectionPool

Inherits:
EM::Synchrony::ConnectionPool
  • Object
show all
Defined in:
lib/emmy_extends/activerecord/connection_pool.rb

Instance Method Summary collapse

Instance Method Details

#acquire(fiber) ⇒ Object



16
17
18
19
# File 'lib/emmy_extends/activerecord/connection_pool.rb', line 16

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

#affected_rows(*args, &blk) ⇒ Object



25
26
27
28
29
# File 'lib/emmy_extends/activerecord/connection_pool.rb', line 25

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

#connectionObject



21
22
23
# File 'lib/emmy_extends/activerecord/connection_pool.rb', line 21

def connection
  acquire(Fiber.current)
end

#execute(async) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/emmy_extends/activerecord/connection_pool.rb', line 4

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