Class: ConfCtl::ParallelExecutor
- Inherits:
-
Object
- Object
- ConfCtl::ParallelExecutor
- Defined in:
- lib/confctl/parallel_executor.rb
Instance Attribute Summary collapse
-
#thread_count ⇒ Object
readonly
Returns the value of attribute thread_count.
Instance Method Summary collapse
- #add(&block) ⇒ Object
-
#initialize(threads) ⇒ ParallelExecutor
constructor
A new instance of ParallelExecutor.
- #run ⇒ Object
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_count ⇒ Object (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 |
#run ⇒ Object
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 |