summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-05-17 21:14:11 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-05-17 21:14:11 -0700
commitb198db2ddf1664cd32389f13ad6284b66d80e9cb (patch)
tree9406200fc20fb031034ff3bc19447551cfd0c8f3 /lib/chef/chef_fs
parent09f81fcbee13c7939bac1f8db4e6cac5a85ce0d7 (diff)
downloadchef-b198db2ddf1664cd32389f13ad6284b66d80e9cb.tar.gz
Add parallel_do method for when you don't care about output
Diffstat (limited to 'lib/chef/chef_fs')
-rw-r--r--lib/chef/chef_fs/parallelizer.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/chef/chef_fs/parallelizer.rb b/lib/chef/chef_fs/parallelizer.rb
index 8996304675..25aaffaab0 100644
--- a/lib/chef/chef_fs/parallelizer.rb
+++ b/lib/chef/chef_fs/parallelizer.rb
@@ -9,6 +9,7 @@ class Chef
def self.threads=(value)
if @@threads != value
@@threads = value
+ @@parallelizer.kill
@@parallelizer = nil
end
end
@@ -17,8 +18,12 @@ class Chef
@@parallelizer ||= Parallelizer.new(@@threads)
end
- def self.parallelize(enumerator, options = {}, &block)
- parallelizer.parallelize(enumerator, options, &block)
+ def self.parallelize(enumerable, options = {}, &block)
+ parallelizer.parallelize(enumerable, options, &block)
+ end
+
+ def self.parallel_do(enumerable, options = {}, &block)
+ parallelizer.parallel_do(enumerable, options, &block)
end
def initialize(threads)
@@ -33,13 +38,19 @@ class Chef
ParallelEnumerable.new(@tasks, enumerable, options, &block)
end
- def stop
+ def parallel_do(enumerable, options = {}, &block)
+ ParallelEnumerable.new(@tasks, enumerable, options.merge(:ordered => false), &block).wait
+ end
+
+ def kill
@threads.each do |thread|
Thread.kill(thread)
end
@threads = []
end
+ private
+
def worker_loop
while true
begin
@@ -61,6 +72,8 @@ class Chef
# order). Default: true
# :main_thread_processing [true|false] - whether the main thread pulling
# on each() is allowed to process inputs. Default: true
+ # NOTE: If you set this to false, parallelizer.kill will stop each()
+ # in its tracks, so you need to know for sure that won't happen.
def initialize(parent_task_queue, enumerable, options, &block)
@task_queue = Queue.new
@parent_task_queue = parent_task_queue