module Concurrent::Async
def self.included(base)
def self.included(base) base.singleton_class.send(:alias_method, :original_new, :new) base.extend(ClassMethods) super(base) end
def self.validate_argc(obj, method, *args)
- See: http://www.ruby-doc.org/core-2.1.0/BasicObject.html#method-i-method_missing - BasicObject#method_missing
See: http://ruby-doc.org/core-2.1.0/Object.html#method-i-respond_to-3F - Object#respond_to?
See: http://www.ruby-doc.org/core-2.1.1/Method.html#method-i-arity - Method#arity
Other tags:
- Note: - This check is imperfect because of the way Ruby reports the arity of
Raises:
-
(ArgumentError)
- the given `args` do not match the arity of `method` -
(NameError)
- the object does not respond to `method` method
Parameters:
-
args
(Array
) -- zero or more arguments for the arity check -
method
(Symbol
) -- the method to check the object for -
obj
(Object
) -- the object to check against
def self.validate_argc(obj, method, *args) argc = args.length arity = obj.method(method).arity if arity >= 0 && argc != arity raise ArgumentError.new("wrong number of arguments (#{argc} for #{arity})") elsif arity < 0 && (arity = (arity + 1).abs) > argc raise ArgumentError.new("wrong number of arguments (#{argc} for #{arity}..*)") end end
def async
-
(ArgumentError)
- the given `args` do not match the arity of -
(NameError)
- the object does not respond to the requested method
Returns:
-
(Concurrent::IVar)
- the pending result of the asynchronous operation
Other tags:
- Note: - The method call is guaranteed to be thread safe with respect to
def async @__async_delegator__ end
def await
-
(ArgumentError)
- the given `args` do not match the arity of the -
(NameError)
- the object does not respond to the requested method
Returns:
-
(Concurrent::IVar)
- the completed result of the synchronous operation
def await @__await_delegator__ end
def init_synchronization
- Note: - This method *must* be called immediately upon object construction.
def init_synchronization return self if defined?(@__async_initialized__) && @__async_initialized__ @__async_initialized__ = true @__async_delegator__ = AsyncDelegator.new(self) @__await_delegator__ = AwaitDelegator.new(@__async_delegator__) self end