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.



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

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

Instance Attribute Details

#encoderObject

Returns the value of attribute encoder.



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

def encoder
  @encoder
end

#signal_queueObject

Returns the value of attribute signal_queue.



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

def signal_queue
  @signal_queue
end

#streamObject

Returns the value of attribute stream.



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

def stream
  @stream
end

#validate_eventObject

Returns the value of attribute validate_event.



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

def validate_event
  @validate_event
end

Instance Method Details

#emit(type, params) ⇒ Object



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

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



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

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

#signal(type, event) ⇒ Object



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

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