Class: Bg::Asyncable::Wrapper
- Inherits:
-
Object
- Object
- Bg::Asyncable::Wrapper
- Includes:
- Concurrent::Async
- Defined in:
- lib/bg/asyncable.rb
Instance Method Summary collapse
-
#initialize(object, wait: 0) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #invoke_method(name, *args) ⇒ Object
Constructor Details
#initialize(object, wait: 0) ⇒ Wrapper
Returns a new instance of Wrapper.
9 10 11 12 13 14 15 |
# File 'lib/bg/asyncable.rb', line 9 def initialize(object, wait: 0) # IMPORTANT: call super without any arguments # https://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Async.html super() @object = object @wait = wait.to_f end |
Instance Method Details
#invoke_method(name, *args) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/bg/asyncable.rb', line 17 def invoke_method(name, *args) sleep @wait if @wait > 0 base = self.is_a?(::ActiveRecord::Base) ? self.class : ::ActiveRecord::Base base.connection_pool.with_connection do @object.send name, *args end end |