Class: EM::Synchrony::ActiveRecord::ConnectionPool
- Inherits:
-
ConnectionPool
- Object
- ConnectionPool
- EM::Synchrony::ActiveRecord::ConnectionPool
- Defined in:
- lib/em-synchrony/activerecord.rb
Instance Method Summary collapse
- #acquire(fiber) ⇒ Object
-
#affected_rows(*args, &blk) ⇒ Object
via method_missing affected_rows will be recognized as async method.
- #connection ⇒ Object
-
#execute(async) ⇒ Object
consider connection acquired.
Instance Method Details
#acquire(fiber) ⇒ Object
86 87 88 89 |
# File 'lib/em-synchrony/activerecord.rb', line 86 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
96 97 98 99 100 |
# File 'lib/em-synchrony/activerecord.rb', line 96 def affected_rows(*args, &blk) execute(false) do |conn| conn.send(:affected_rows, *args, &blk) end end |
#connection ⇒ Object
91 92 93 |
# File 'lib/em-synchrony/activerecord.rb', line 91 def connection acquire(Fiber.current) end |
#execute(async) ⇒ Object
consider connection acquired
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/em-synchrony/activerecord.rb', line 74 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 |