aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/concurrency
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-03-11 07:45:24 +1030
committerMatthew Draper <matthew@trebex.net>2016-03-11 07:45:24 +1030
commitb50f5a5ac6fc554eaad3138cb42f678a41794771 (patch)
tree9295d66a5f511536a054418840f776f96af56d03 /activesupport/lib/active_support/concurrency
parentbf79b81740538e96c4881a7c27775a8faf966555 (diff)
downloadrails-b50f5a5ac6fc554eaad3138cb42f678a41794771.tar.gz
rails-b50f5a5ac6fc554eaad3138cb42f678a41794771.tar.bz2
rails-b50f5a5ac6fc554eaad3138cb42f678a41794771.zip
Don't inherit from Concurrent::CountDownLatch
That class mangles .new, which interferes with our deprecation warning. More generally, it suggests we shouldn't be subclassing without a very good reason, and avoiding one allocation doesn't seem to meet that criteria. In passing, recommend the simpler Concurrent::Event for the common count=1 case.
Diffstat (limited to 'activesupport/lib/active_support/concurrency')
-rw-r--r--activesupport/lib/active_support/concurrency/latch.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/concurrency/latch.rb b/activesupport/lib/active_support/concurrency/latch.rb
index 4abe5ece6f..35074265b8 100644
--- a/activesupport/lib/active_support/concurrency/latch.rb
+++ b/activesupport/lib/active_support/concurrency/latch.rb
@@ -2,17 +2,24 @@ require 'concurrent/atomic/count_down_latch'
module ActiveSupport
module Concurrency
- class Latch < Concurrent::CountDownLatch
+ class Latch
def initialize(count = 1)
- ActiveSupport::Deprecation.warn("ActiveSupport::Concurrency::Latch is deprecated. Please use Concurrent::CountDownLatch instead.")
- super(count)
+ if count == 1
+ ActiveSupport::Deprecation.warn("ActiveSupport::Concurrency::Latch is deprecated. Please use Concurrent::Event instead.")
+ else
+ ActiveSupport::Deprecation.warn("ActiveSupport::Concurrency::Latch is deprecated. Please use Concurrent::CountDownLatch instead.")
+ end
+
+ @inner = Concurrent::CountDownLatch.new(count)
end
- alias_method :release, :count_down
+ def release
+ @inner.count_down
+ end
def await
- wait(nil)
+ @inner.wait(nil)
end
end
end