class FutureRecords::Result

Public Class Methods

new() { || ... } click to toggle source
# 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

Public Instance Methods

records() click to toggle source
# 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