Module: Async
- Defined in:
- lib/async.rb
Overview
a module for executing code asynchronously in another thread. This is disabled
Instance Method Summary collapse
-
#async ⇒ Thread
Execute the given block in another thread, but only in production.
Instance Method Details
#async ⇒ Thread
Execute the given block in another thread, but only in production. During development, the block executes on the current thread
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/async.rb', line 10 def async raise "A block must be provided" unless block_given? if Async.enabled Thread.new do # ensure that this thread uses a new connection to the database and returns it to the pool when done. ActiveRecord::Base.connection_pool.with_connection do yield end end else yield Thread.current end end |