Class: Termplot::Consumers::BaseConsumer::ProducerPool
- Inherits:
-
Object
- Object
- Termplot::Consumers::BaseConsumer::ProducerPool
- Defined in:
- lib/termplot/consumers/base_consumer.rb
Instance Method Summary collapse
- #add_producer(producer) ⇒ Object
-
#initialize ⇒ ProducerPool
constructor
A new instance of ProducerPool.
- #start ⇒ Object
- #start_and_block ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize ⇒ ProducerPool
Returns a new instance of ProducerPool.
100 101 102 103 |
# File 'lib/termplot/consumers/base_consumer.rb', line 100 def initialize @producers = [] @threads = [] end |
Instance Method Details
#add_producer(producer) ⇒ Object
123 124 125 |
# File 'lib/termplot/consumers/base_consumer.rb', line 123 def add_producer(producer) producers.push(producer) end |
#start ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/termplot/consumers/base_consumer.rb', line 105 def start # Run Producers with producers @threads = producers.map do |producer| Thread.new do producer.run end end end |
#start_and_block ⇒ Object
118 119 120 121 |
# File 'lib/termplot/consumers/base_consumer.rb', line 118 def start_and_block start wait end |
#wait ⇒ Object
114 115 116 |
# File 'lib/termplot/consumers/base_consumer.rb', line 114 def wait threads.each(&:join) end |