Class: Aws::EventEmitter
- Inherits:
-
Object
- Object
- Aws::EventEmitter
- Defined in:
- gems/aws-sdk-core/lib/aws-sdk-core/event_emitter.rb
Instance Attribute Summary collapse
-
#encoder ⇒ Object
Returns the value of attribute encoder.
-
#signal_queue ⇒ Object
Returns the value of attribute signal_queue.
-
#stream ⇒ Object
Returns the value of attribute stream.
-
#validate_event ⇒ Object
Returns the value of attribute validate_event.
Instance Method Summary collapse
-
#emit(type, params) ⇒ Object
-
#initialize ⇒ EventEmitter
constructor
A new instance of EventEmitter.
-
#on(type, callback) ⇒ Object
-
#signal(type, event) ⇒ Object
Constructor Details
#initialize ⇒ EventEmitter
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
#encoder ⇒ Object
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_queue ⇒ Object
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 |
#stream ⇒ Object
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_event ⇒ Object
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 |