class Concurrent::Async::AsyncDelegator
@!visibility private
Delegates asynchronous, thread-safe method calls to the wrapped object.
def initialize(delegate)
-
delegate
(Object
) -- the object to wrap and delegate method calls to
def initialize(delegate) super() @delegate = delegate @queue = [] @executor = Concurrent.global_io_executor 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) ivar = Concurrent::IVar.new synchronize do @queue.push [ivar, method, args, block] @executor.post { perform } if @queue.length == 1 end ivar end
def perform
This method must be called from within the executor. It must not be
Perform all enqueued tasks.
def perform loop do ivar, method, args, block = synchronize { @queue.first } break unless ivar # queue is empty begin ivar.set(@delegate.send(method, *args, &block)) rescue => error ivar.fail(error) end synchronize do @queue.shift return if @queue.empty? end end end
def respond_to_missing?(method, include_private = false)
-
method
(Symbol
) -- the method being called
def respond_to_missing?(method, include_private = false) @delegate.respond_to?(method) || super end