Class: Gracefully::MutexBasedSynchronizedCounter
- Defined in:
- lib/gracefully/mutex_based_synchronized_counter.rb
Overview
The counter equipped with the possibly easiest kind of synchronization.
Instance Method Summary collapse
- #count ⇒ Object
- #increment! ⇒ Object
-
#initialize(counter) ⇒ MutexBasedSynchronizedCounter
constructor
A new instance of MutexBasedSynchronizedCounter.
- #reset! ⇒ Object
Constructor Details
#initialize(counter) ⇒ MutexBasedSynchronizedCounter
Returns a new instance of MutexBasedSynchronizedCounter.
9 10 11 12 |
# File 'lib/gracefully/mutex_based_synchronized_counter.rb', line 9 def initialize(counter) @counter = counter @mutex = Mutex.new end |
Instance Method Details
#count ⇒ Object
26 27 28 |
# File 'lib/gracefully/mutex_based_synchronized_counter.rb', line 26 def count @counter.count end |
#increment! ⇒ Object
20 21 22 23 24 |
# File 'lib/gracefully/mutex_based_synchronized_counter.rb', line 20 def increment! @mutex.synchronize do @counter.increment! end end |
#reset! ⇒ Object
14 15 16 17 18 |
# File 'lib/gracefully/mutex_based_synchronized_counter.rb', line 14 def reset! @mutex.synchronize do @counter.reset! end end |