Class: ConfCtl::ParallelExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/parallel_executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(threads) ⇒ ParallelExecutor

Returns a new instance of ParallelExecutor.



5
6
7
8
9
10
11
# File 'lib/confctl/parallel_executor.rb', line 5

def initialize(threads)
  @thread_count = threads
  @threads = []
  @queue = Queue.new
  @retvals = []
  @mutex = Mutex.new
end

Instance Attribute Details

#thread_countObject (readonly)

Returns the value of attribute thread_count.



3
4
5
# File 'lib/confctl/parallel_executor.rb', line 3

def thread_count
  @thread_count
end

Instance Method Details

#add(&block) ⇒ Object



13
14
15
# File 'lib/confctl/parallel_executor.rb', line 13

def add(&block)
  queue << block
end

#runObject



17
18
19
20
21
22
23
24
# File 'lib/confctl/parallel_executor.rb', line 17

def run
  thread_count.times do
    threads << Thread.new { worker }
  end

  threads.each(&:join)
  retvals
end