class Concurrent::Async::AsyncDelegator
:nodoc:
@!visibility private
Delegates asynchronous, thread-safe method calls to the wrapped object.
def initialize(delegate, executor, mutex)
-
mutex(Mutex) -- the mutex lock to use when delegating method calls -
delegate(Object) -- the object to wrap and delegate method calls to
def initialize(delegate, executor, mutex) @delegate = delegate @executor = executor @mutex = mutex end
def method_missing(method, *args, &block)
-
(ArgumentError)- the given `args` do not match the arity of `method` -
(NameError)- the object does not respond to `method` method
Returns:
-
(IVar)- the result of the method call
Parameters:
-
args(Array) -- zero or more arguments to the method -
method(Symbol) -- the method being called
def method_missing(method, *args, &block) super unless @delegate.respond_to?(method) Async::validate_argc(@delegate, method, *args) self.define_singleton_method(method) do |*args| Async::validate_argc(@delegate, method, *args) Concurrent::Future.execute(executor: @executor) do mutex.synchronize do @delegate.send(method, *args, &block) end end end self.send(method, *args) end