Sha256: c47cdad58847ed28eefa0bb584e5ba3bed24f98a436b9d25d7ea2311837ea94f

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8

module FiniteMachine
  # An asynchronouse call representation
  #
  # Used internally by {EventQueue} to schedule events
  #
  # @api private
  class AsyncCall
    include Threadable

    # Create asynchronous call instance
    #
    # @param [Object] context
    # @param [Callable] callable
    # @param [Array] args
    # @param [#call] block
    #
    # @example
    #   AsyncCall.new(context, Callable.new(:method), :a, :b)
    #
    # @return [self]
    #
    # @api public
    def initialize(context, callable, *args, &block)
      @context   = context
      @callable  = callable
      @arguments = args.dup
      @block     = block
      @mutex     = Mutex.new
      freeze
    end

    # Dispatch the event to the context
    #
    # @return [nil]
    #
    # @api private
    def dispatch
      @mutex.synchronize do
        callable.call(context, *arguments, &block)
      end
    end

    protected

    attr_threadsafe :context

    attr_threadsafe :callable

    attr_threadsafe :arguments

    attr_threadsafe :block
  end # AsyncCall
end # FiniteMachine

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
finite_machine-0.11.3 lib/finite_machine/async_call.rb
finite_machine-0.11.2 lib/finite_machine/async_call.rb
finite_machine-0.11.1 lib/finite_machine/async_call.rb
finite_machine-0.11.0 lib/finite_machine/async_call.rb
finite_machine-0.10.2 lib/finite_machine/async_call.rb
finite_machine-0.10.1 lib/finite_machine/async_call.rb
finite_machine-0.10.0 lib/finite_machine/async_call.rb