Class: ActiveRecord::Deferrable::Result
- Inherits:
- ActiveSupport::BasicObject
- Defined in:
- lib/active_record/connection_adapters/mysqlplus_adapter/deferrable/result.rb
Instance Method Summary collapse
-
#defer!(deferrable) ⇒ Object
Calls a given procedure in a background Thread, on another connection from the pool.Guarantees that said connection is checked back in on completion.
-
#initialize(&deferrable) ⇒ Result
constructor
Represents a Lazy Loaded resultset.
-
#method_missing(*args, &block) ⇒ Object
Delegates to the background Thread.
-
#validate! ⇒ Object
Re-raise any Exceptions from the background Thread.
Constructor Details
#initialize(&deferrable) ⇒ Result
Represents a Lazy Loaded resultset. Any method calls would block if the result hasn’t yet been processed in a background Thread.
9 10 11 |
# File 'lib/active_record/connection_adapters/mysqlplus_adapter/deferrable/result.rb', line 9 def initialize( &deferrable ) defer!( deferrable ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
Delegates to the background Thread.
32 33 34 35 36 |
# File 'lib/active_record/connection_adapters/mysqlplus_adapter/deferrable/result.rb', line 32 def method_missing(*args, &block) @_result ||= @result.value validate! @_result.send(*args, &block) end |
Instance Method Details
#defer!(deferrable) ⇒ Object
Calls a given procedure in a background Thread, on another connection from the pool.Guarantees that said connection is checked back in on completion.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_record/connection_adapters/mysqlplus_adapter/deferrable/result.rb', line 17 def defer!( deferrable ) @result = ::Thread.new( deferrable ) do |deferrable| begin deferrable.call rescue => exception exception ensure ::ActiveRecord::Base.connection_pool.release_connection end end self end |
#validate! ⇒ Object
Re-raise any Exceptions from the background Thread.
40 41 42 |
# File 'lib/active_record/connection_adapters/mysqlplus_adapter/deferrable/result.rb', line 40 def validate! raise @_result if @_result.is_a?( ::Exception ) end |