class Concurrent::Async::AwaitDelegator
:nodoc:
@!visibility private
Delegates synchronous, thread-safe method calls to the wrapped object.
def initialize(delegate, 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, mutex) @delegate = delegate @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) ivar = Concurrent::IVar.new value, reason = nil, nil begin mutex.synchronize do value = @delegate.send(method, *args, &block) end rescue => reason # caught ensure return ivar.complete(reason.nil?, value, reason) end end self.send(method, *args) end