Class: FutureRecords::Result
- Inherits:
-
Object
- Object
- FutureRecords::Result
- Defined in:
- lib/future_records.rb
Instance Method Summary collapse
-
#initialize(&block) ⇒ Result
constructor
A new instance of Result.
- #records ⇒ Object
Constructor Details
#initialize(&block) ⇒ Result
Returns a new instance of Result.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/future_records.rb', line 38 def initialize(&block) @block = block @thread = Thread.new do @records = yield if Thread.current[:child_thread_connections] Thread.current[:child_thread_connections].map {|conn| conn.pool}.uniq.each do |pool| pool.release_connection end end end end |
Instance Method Details
#records ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/future_records.rb', line 50 def records @thread.join @records rescue ::ActiveRecord::ConnectionTimeoutError ActiveRecord::Base.logger.info 'FutureRecords: Failed to obtain a connection. Falling back to non-threaded query' @block.call end |