Class: Termplot::Consumers::BaseConsumer::ProducerPool

Inherits:
Object
  • Object
show all
Defined in:
lib/termplot/consumers/base_consumer.rb

Instance Method Summary collapse

Constructor Details

#initializeProducerPool

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

#startObject



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_blockObject



118
119
120
121
# File 'lib/termplot/consumers/base_consumer.rb', line 118

def start_and_block
  start
  wait
end

#waitObject



114
115
116
# File 'lib/termplot/consumers/base_consumer.rb', line 114

def wait
  threads.each(&:join)
end