class Proxy
Represents an asynchronous proxy that wraps an object and executes its methods in a separate thread.
Nested
Definitions
def initialize(target)
Initialize a new proxy for the target object.
Signature
-
parameter
target
Object
The object to wrap with asynchronous method execution.
Implementation
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
def method_missing(*arguments, return_value: :wait, **options, &block)
Signature
-
parameter
return_value
Symbol
One of :ignore, :promise or :wait.
Implementation
def method_missing(*arguments, return_value: :wait, **options, &block)
unless return_value == :ignore
result = Promise.new
end
@queue.push([arguments, options, block, result])
if return_value == :promise
return result
else
return result&.wait
end
end