Class: Aws::EventEmitter
- Inherits:
- 
      Object
      
        - Object
- Aws::EventEmitter
 
- Defined in:
- 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 | # File 'lib/aws-sdk-core/event_emitter.rb', line 6 def initialize @listeners = {} @validate_event = true @signal_queue = Queue.new end | 
Instance Attribute Details
#encoder ⇒ Object
Returns the value of attribute encoder.
| 14 15 16 | # File 'lib/aws-sdk-core/event_emitter.rb', line 14 def encoder @encoder end | 
#signal_queue ⇒ Object
Returns the value of attribute signal_queue.
| 18 19 20 | # File 'lib/aws-sdk-core/event_emitter.rb', line 18 def signal_queue @signal_queue end | 
#stream ⇒ Object
Returns the value of attribute stream.
| 12 13 14 | # File 'lib/aws-sdk-core/event_emitter.rb', line 12 def stream @stream end | 
#validate_event ⇒ Object
Returns the value of attribute validate_event.
| 16 17 18 | # File 'lib/aws-sdk-core/event_emitter.rb', line 16 def validate_event @validate_event end | 
Instance Method Details
#emit(type, params) ⇒ Object
| 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | # File 'lib/aws-sdk-core/event_emitter.rb', line 31 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 | 
#on(type, callback) ⇒ Object
| 20 21 22 | # File 'lib/aws-sdk-core/event_emitter.rb', line 20 def on(type, callback) (@listeners[type] ||= []) << callback end | 
#signal(type, event) ⇒ Object
| 24 25 26 27 28 29 | # File 'lib/aws-sdk-core/event_emitter.rb', line 24 def signal(type, event) return unless @listeners[type] @listeners[type].each do |listener| listener.call(event) if event.event_type == type end end |