Class: Bg::Asyncable
- Inherits:
-
Object
- Object
- Bg::Asyncable
- Defined in:
- lib/bg/asyncable.rb
Defined Under Namespace
Modules: Behavior Classes: Wrapper
Instance Method Summary collapse
-
#initialize(object, wait: 0) ⇒ Asyncable
constructor
A new instance of Asyncable.
- #method_missing(name, *args) ⇒ Object
- #respond_to?(name) ⇒ Boolean
Constructor Details
#initialize(object, wait: 0) ⇒ Asyncable
Returns a new instance of Asyncable.
32 33 34 35 |
# File 'lib/bg/asyncable.rb', line 32 def initialize(object, wait: 0) @object = object @wait = wait.to_f end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bg/asyncable.rb', line 37 def method_missing(name, *args) if @object.respond_to? name raise ::ArgumentError.new("blocks are not supported") if block_given? begin wrapped = ::Bg::Asyncable::Wrapper.new(@object, wait: @wait) wrapped.async.invoke_method name, *args rescue ::StandardError => e raise ::ArgumentError.new("Failed to execute method asynchronously! <#{@object.class.name}##{name}> #{e.}") ensure return end end super end |
Instance Method Details
#respond_to?(name) ⇒ Boolean
52 53 54 55 |
# File 'lib/bg/asyncable.rb', line 52 def respond_to?(name) return true if @object.respond_to? name super end |