Class: Farce::Concurrent::CountDownLatch
- Inherits:
-
Object
- Object
- Farce::Concurrent::CountDownLatch
- Includes:
- Internal::Noncopyable, Shareable::Delegated
- Defined in:
- lib/farce/concurrent/count_down_latch.rb
Overview
A replacement for concurrent-ruby's CountDownLatch implementation.
Instance Attribute Summary collapse
- #count ⇒ BasicObject readonly
Instance Method Summary collapse
-
#count_down
Decrements the count of the latch by 1 if it is above 0.
-
#initialize(count = 1) ⇒ CountDownLatch
constructor
A new instance of CountDownLatch.
-
#wait(timeout = nil) ⇒ Boolean
Waits until the count reaches 0 or the optional timeout is reached.
Methods included from Internal::Noncopyable
Methods included from Shareable
Constructor Details
#initialize(count = 1) ⇒ CountDownLatch
Returns a new instance of CountDownLatch.
15 16 17 18 19 |
# File 'lib/farce/concurrent/count_down_latch.rb', line 15 def initialize(count = 1) raise ArgumentError, "count must be a non-negative integer" unless count.is_a?(Integer) && count >= 0 @counter = Counter.new(count) super() end |
Instance Attribute Details
#count ⇒ BasicObject (readonly)
23 |
# File 'lib/farce/concurrent/count_down_latch.rb', line 23 def count = @counter.value |
Instance Method Details
#count_down
This method returns an undefined value.
Decrements the count of the latch by 1 if it is above 0.
27 |
# File 'lib/farce/concurrent/count_down_latch.rb', line 27 def count_down = @counter.decrement_if_above(0) |
#wait(timeout = nil) ⇒ Boolean
Waits until the count reaches 0 or the optional timeout is reached.
32 |
# File 'lib/farce/concurrent/count_down_latch.rb', line 32 def wait(timeout = nil) = !!@counter.wait_while_above(0, timeout:) # rubocop:disable Naming/PredicateMethod |