Class: Aws::EventEmitter

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventEmitter

Returns a new instance of EventEmitter.



4
5
6
7
8
9
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 4

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

Instance Attribute Details

#encoderObject

Returns the value of attribute encoder.



13
14
15
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 13

def encoder
  @encoder
end

#signal_queueObject

Returns the value of attribute signal_queue.



17
18
19
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 17

def signal_queue
  @signal_queue
end

#streamObject

Returns the value of attribute stream.



11
12
13
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 11

def stream
  @stream
end

#validate_eventObject

Returns the value of attribute validate_event.



15
16
17
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 15

def validate_event
  @validate_event
end

Instance Method Details

#emit(type, params) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 30

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
  _ready_for_events?
  @stream.data(
    @encoder.encode(type, params),
    end_stream: type == :end_stream
  )
end

#on(type, callback) ⇒ Object



19
20
21
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 19

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

#signal(type, event) ⇒ Object



23
24
25
26
27
28
# File 'gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb', line 23

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