Class: Async::Actor::Proxy
- Inherits:
- BasicObject
- Defined in:
- lib/async/actor/proxy.rb
Defined Under Namespace
Classes: Finalizer
Instance Method Summary collapse
-
#initialize(target) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(*arguments, return_value: :wait, **options, &block) ⇒ Object
Constructor Details
#initialize(target) ⇒ Proxy
Returns a new instance of Proxy.
25 26 27 28 29 30 31 32 33 |
# File 'lib/async/actor/proxy.rb', line 25 def initialize(target) @target = target @queue = ::Thread::Queue.new @thread = __start__ # Define a finalizer to ensure the thread is closed: ::ObjectSpace.define_finalizer(self, Finalizer.new(@queue, @thread)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*arguments, return_value: :wait, **options, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/async/actor/proxy.rb', line 36 def method_missing(*arguments, return_value: :wait, **, &block) unless return_value == :ignore result = Variable.new end @queue.push([arguments, , block, result]) if return_value == :promise return result else return result&.get end end |