Class: Async::Actor::Proxy

Inherits:
BasicObject
Defined in:
lib/async/actor/proxy.rb

Defined Under Namespace

Classes: Finalizer

Instance Method Summary collapse

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, **options, &block)
  unless return_value == :ignore
    result = Variable.new
  end
  
  @queue.push([arguments, options, block, result])
  
  if return_value == :promise
    return result
  else
    return result&.get
  end
end