Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created June 20, 2019 22:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BetterProgramming/ce8bef146a354e59df949aa6bd9c921d to your computer and use it in GitHub Desktop.
Save BetterProgramming/ce8bef146a354e59df949aa6bd9c921d to your computer and use it in GitHub Desktop.
threads << Thread.new do ActiveRecord::Base.connection_pool.with_connection do
# needed because otherwise the connection pool can run
# out of connections
t = Thread.current
t[:variable_name] = Model.find_by(column: data)
end
end
joined_threads = threads.map &:join
# do something with the thread local variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment