Class: Concurrent::Actor::Utils::Broadcast
- Inherits:
- 
      RestartingContext
      
        - Object
- AbstractContext
- RestartingContext
- Concurrent::Actor::Utils::Broadcast
 
- Defined in:
- lib/concurrent/actor/utils/broadcast.rb
Overview
Allows to build pub/sub easily.
Instance Attribute Summary
Attributes inherited from AbstractContext
Instance Method Summary collapse
- 
  
    
      #filtered_receivers  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    override to define different behaviour, filtering etc. 
- 
  
    
      #initialize  ⇒ Broadcast 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Broadcast. 
- #on_message(message) ⇒ Object
Methods inherited from RestartingContext
Methods inherited from AbstractContext
#ask, #behaviour_definition, #dead_letter_routing, #default_reference_class, #envelope, #on_envelope, #on_event, #pass, #tell
Methods included from InternalDelegations
#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect, #terminate!
Methods included from PublicDelegations
#context_class, #executor, #name, #parent, #path, #reference
Methods included from TypeCheck
#Child!, #Child?, #Match!, #Match?, #Type!, #Type?
Constructor Details
#initialize ⇒ Broadcast
Returns a new instance of Broadcast.
| 22 23 24 | # File 'lib/concurrent/actor/utils/broadcast.rb', line 22 def initialize @receivers = Set.new end | 
Instance Method Details
#filtered_receivers ⇒ Object
override to define different behaviour, filtering etc
| 45 46 47 | # File 'lib/concurrent/actor/utils/broadcast.rb', line 45 def filtered_receivers @receivers end | 
#on_message(message) ⇒ Object
| 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # File 'lib/concurrent/actor/utils/broadcast.rb', line 26 def () case when :subscribe if envelope.sender.is_a? Reference @receivers.add envelope.sender true else false end when :unsubscribe !!@receivers.delete(envelope.sender) when :subscribed? @receivers.include? envelope.sender else filtered_receivers.each { |r| r << } end end |