From 7e8fbca79ebfd04c259e74148cd31e59c2d65451 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Tue, 28 Oct 2014 18:00:29 -0700 Subject: [PATCH] Add thread_safe for handling the @children inside of Hermann::Producer This isn't comprehensive, still debating a comprehensive approach to #50 that I'm happy with References #50 --- hermann.gemspec | 1 + lib/hermann/producer.rb | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hermann.gemspec b/hermann.gemspec index d72c5cd..01ecd78 100644 --- a/hermann.gemspec +++ b/hermann.gemspec @@ -25,6 +25,7 @@ Gem::Specification.new do |s| s.add_dependency 'concurrent-ruby', '~> 0.7.0' s.add_dependency "zk", "~> 1.9.4" + s.add_dependency 'thread_safe', '~> 0.3.4' if RUBY_PLATFORM == "java" #IMPORTANT: make sure that jar-dependencies is only a development dependency of your gem. if it is a runtime dependencies the require_jars file will be overwritten during installation. diff --git a/lib/hermann/producer.rb b/lib/hermann/producer.rb index 80a2dbd..5a9dc12 100644 --- a/lib/hermann/producer.rb +++ b/lib/hermann/producer.rb @@ -1,7 +1,8 @@ +require 'thread_safe' + require 'hermann' require 'hermann/result' - if RUBY_PLATFORM == "java" require 'hermann/provider/java_producer' else @@ -26,7 +27,7 @@ module Hermann end # We're tracking children so we can make sure that at Producer exit we # make a reasonable attempt to clean up outstanding result objects - @children = [] + @children = ThreadSafe::Array.new end # @return [Boolean] True if our underlying producer object thinks it's