Sha256: 4bd65c7da9518215e51ec59f400303a6f5bc29d26a828599e37dbdf2ff4fd885

Contents?: true

Size: 1.02 KB

Versions: 31

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Aws
  class EventEmitter

    def initialize
      @listeners = {}
      @validate_event = true
      @signal_queue = Queue.new
    end

    attr_accessor :stream

    attr_accessor :encoder

    attr_accessor :validate_event

    attr_accessor :signal_queue

    def on(type, callback)
      (@listeners[type] ||= []) << callback
    end

    def signal(type, event)
      return unless @listeners[type]
      @listeners[type].each do |listener|
        listener.call(event) if event.event_type == type
      end
    end

    def emit(type, params)
      unless @stream
        raise Aws::Errors::SignalEventError.new(
          "Singaling events before making async request"\
          " is not allowed."
        )
      end
      if @validate_event && type != :end_stream
        Aws::ParamValidator.validate!(
          @encoder.rules.shape.member(type), params)
      end
      @stream.data(
        @encoder.encode(type, params),
        end_stream: type == :end_stream
      )
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.210.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/event_emitter.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/event_emitter.rb