Created
December 5, 2012 00:36
-
-
Save dougcole/4210726 to your computer and use it in GitHub Desktop.
Simple class for running an ActiveRecord query in a separate thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConcurrentQuery < BasicObject | |
def initialize(&block) | |
@query = ::Thread.new do | |
result = begin | |
block.call | |
ensure | |
::ActiveRecord::Base.connection_pool.release_connection | |
end | |
result | |
end | |
end | |
def method_missing(method_name, *args, &block) | |
@query.value.send(method_name, *args, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment