# encoding: utf-8

module FiniteMachine
  # An asynchronous messages proxy
  class AsyncProxy

    attr_reader :context

    # Initialize an AsynxProxy
    #
    # @param [Object] context
    #   the context this proxy is associated with
    #
    # @api private
    def initialize(context)
      @context = context
    end

    # Delegate asynchronous event to event queue
    #
    # @api private
    def method_missing(method_name, *args, &block)
      @event_queue = FiniteMachine.event_queue
      @event_queue << AsyncCall.build(@context, Callable.new(method_name), *args, &block)
    end
  end # AsyncProxy
end # FiniteMachine

# encoding: utf-8

module FiniteMachine
  # An asynchronous messages proxy
  class AsyncProxy
    include Threadable
    include ThreadContext

    attr_threadsafe :context

    # Initialize an AsynxProxy
    #
    # @param [Object] context
    #   the context this proxy is associated with
    #
    # @api private
    def initialize(context)
      self.context = context
    end

    # Delegate asynchronous event to event queue
    #
    # @api private
    def method_missing(method_name, *args, &block)
      event_queue << AsyncCall.build(context, Callable.new(method_name), *args, &block)
    end
  end # AsyncProxy
end # FiniteMachine

Change async proxy to use thread context and threadsafe attribute.
Change async proxy to use thread context and threadsafe attribute.
