Sha256: 7321c9f31ee7b5b6dcb00c5f5ce6d3134753c3d5af719fc85664266541bbc74c

Contents?: true

Size: 947 Bytes

Versions: 1

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

module Emittance
  class Synchronous
    ##
    # The synchronous dispatcher. Runs callbacks one-by-one, in series.
    #
    class Dispatcher < Emittance::Dispatcher
      class << self
        private

        def _process_event(event)
          registrations_for(event).each do |registration|
            event = Emittance::Middleware.down(event)
            registration.call event
          end
        end

        def _register(identifier, _params = {}, &callback)
          registrations = registrations_for identifier
          registrations << callback
          callback
        end

        def _register_method_call(identifier, object, method_name, _params = {})
          register identifier, &lambda_for_method_call(object, method_name)
        end

        def lambda_for_method_call(object, method_name)
          ->(event) { object.send method_name, event }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
emittance-2.0.0.pre.1 lib/emittance/dispatchers/synchronous.rb