Object
Delegates asynchronous, thread-safe method calls to the wrapped object.
@!visibility private
Create a new delegator object wrapping the given delegate, protecting it with the given serializer, and executing it on the given executor. Block if necessary.
@param [Object] delegate the object to wrap and delegate method calls to @param [Concurrent::Delay] executor a `Delay` wrapping the executor on which to execute delegated method calls @param [Concurrent::SerializedExecution] serializer the serializer to use when delegating method calls @param [Boolean] blocking will block awaiting result when `true`
# File lib/concurrent/async.rb, line 145 def initialize(delegate, executor, serializer, blocking = false) @delegate = delegate @executor = executor @serializer = serializer @blocking = blocking end
Delegates method calls to the wrapped object. For performance, dynamically defines the given method on the delegator so that all future calls to `method` will not be directed here.
@param [Symbol] method the method being called @param [Array] args zero or more arguments to the method
@return [IVar] the result of the method call
@raise [NameError] the object does not respond to `method` method @raise [ArgumentError] the given `args` do not match the arity of `method`
# File lib/concurrent/async.rb, line 163 def method_missing(method, *args, &block) super unless @delegate.respond_to?(method) Async::validate_argc(@delegate, method, *args) self.define_singleton_method(method) do |*args2| Async::validate_argc(@delegate, method, *args2) ivar = Concurrent::IVar.new @serializer.post(@executor.value) do begin ivar.set(@delegate.send(method, *args2, &block)) rescue => reason ivar.fail(reason) end end ivar.value if @blocking ivar end self.send(method, *args) end
Generated with the Darkfish Rdoc Generator 2.