Module: RSMP::Distributor
Overview
Class which distributes messages to receivers
Instance Attribute Summary collapse
-
#receivers ⇒ Object
readonly
Returns the value of attribute receivers.
Instance Method Summary collapse
- #add_receiver(receiver) ⇒ Object
- #clear_deferred_distribution ⇒ Object
- #distribute(message) ⇒ Object
- #distribute_error(error, options = {}) ⇒ Object
- #distribute_immediately(message) ⇒ Object
- #distribute_queued ⇒ Object
- #initialize_distributor ⇒ Object
- #inspect ⇒ Object
- #remove_receiver(receiver) ⇒ Object
- #with_deferred_distribution ⇒ Object
Methods included from Inspect
Instance Attribute Details
#receivers ⇒ Object (readonly)
Returns the value of attribute receivers.
4 5 6 |
# File 'lib/rsmp/collect/distributor.rb', line 4 def receivers @receivers end |
Instance Method Details
#add_receiver(receiver) ⇒ Object
38 39 40 41 42 |
# File 'lib/rsmp/collect/distributor.rb', line 38 def add_receiver(receiver) raise ArgumentError unless receiver @receivers << receiver unless @receivers.include? receiver end |
#clear_deferred_distribution ⇒ Object
18 19 20 |
# File 'lib/rsmp/collect/distributor.rb', line 18 def clear_deferred_distribution = [] end |
#distribute(message) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/rsmp/collect/distributor.rb', line 50 def distribute() raise ArgumentError unless if @defer_distribution << else distribute_immediately end end |
#distribute_error(error, options = {}) ⇒ Object
64 65 66 |
# File 'lib/rsmp/collect/distributor.rb', line 64 def distribute_error(error, = {}) @receivers.each { |receiver| receiver.receive_error error, } end |
#distribute_immediately(message) ⇒ Object
60 61 62 |
# File 'lib/rsmp/collect/distributor.rb', line 60 def distribute_immediately() @receivers.each { |receiver| receiver.receive } end |
#distribute_queued ⇒ Object
32 33 34 35 36 |
# File 'lib/rsmp/collect/distributor.rb', line 32 def distribute_queued .each { || distribute_immediately } ensure = [] end |
#initialize_distributor ⇒ Object
12 13 14 15 16 |
# File 'lib/rsmp/collect/distributor.rb', line 12 def initialize_distributor @receivers = [] @defer_distribution = false = [] end |
#inspect ⇒ Object
8 9 10 |
# File 'lib/rsmp/collect/distributor.rb', line 8 def inspect "#<#{self.class.name}:#{object_id}, #{inspector(:@receivers)}>" end |
#remove_receiver(receiver) ⇒ Object
44 45 46 47 48 |
# File 'lib/rsmp/collect/distributor.rb', line 44 def remove_receiver(receiver) raise ArgumentError unless receiver @receivers.delete receiver end |
#with_deferred_distribution ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/rsmp/collect/distributor.rb', line 22 def with_deferred_distribution was = @defer_distribution @defer_distribution = true yield distribute_queued ensure @defer_distribution = was = [] end |