Class: ProducerConsumer::ConsumerPool

Inherits:
WorkerPool
  • Object
show all
Defined in:
lib/producer_consumer/consumer_pool.rb

Overview

A ConsumerPool is a special type of worker pool where the input is another WorkerPool instance.

Instance Attribute Summary

Attributes inherited from WorkerPool

#output_queue

Instance Method Summary collapse

Methods inherited from WorkerPool

#alive?, #run, #wait

Methods included from Enumerable

#consume, #produce

Constructor Details

#initialize(producer, number_of_threads = 1) ⇒ ConsumerPool

Returns a new instance of ConsumerPool.



9
10
11
12
# File 'lib/producer_consumer/consumer_pool.rb', line 9

def initialize(producer, number_of_threads=1)
  @producer = producer
  super([], number_of_threads)
end

Instance Method Details

#do_workObject



14
15
16
17
18
# File 'lib/producer_consumer/consumer_pool.rb', line 14

def do_work
  while @producer.alive? || (not @producer.output_queue.empty?)
    @output_queue << yield(@producer.output_queue.pop)
  end
end