diff --git a/lib/concurrent/atomic/count_down_latch.rb b/lib/concurrent/atomic/count_down_latch.rb index 3ed38ca33..24a5eb146 100644 --- a/lib/concurrent/atomic/count_down_latch.rb +++ b/lib/concurrent/atomic/count_down_latch.rb @@ -20,7 +20,7 @@ class MutexCountDownLatch # @param [Fixnum] count the initial count # # @raise [ArgumentError] if `count` is not an integer or is less than zero - def initialize(count) + def initialize(count = 1) unless count.is_a?(Fixnum) && count >= 0 raise ArgumentError.new('count must be in integer greater than or equal zero') end @@ -75,7 +75,7 @@ def count class JavaCountDownLatch # @!macro count_down_latch_method_initialize - def initialize(count) + def initialize(count = 1) unless count.is_a?(Fixnum) && count >= 0 raise ArgumentError.new('count must be in integer greater than or equal zero') end diff --git a/spec/concurrent/atomic/count_down_latch_spec.rb b/spec/concurrent/atomic/count_down_latch_spec.rb index c9f52162b..1a551ab2b 100644 --- a/spec/concurrent/atomic/count_down_latch_spec.rb +++ b/spec/concurrent/atomic/count_down_latch_spec.rb @@ -18,6 +18,11 @@ described_class.new('foo') }.to raise_error(ArgumentError) end + + it 'defaults the count to 1' do + latch = described_class.new + expect(latch.count).to eq 1 + end end describe '#count' do