Class: Gracefully::MutexBasedSynchronizedCounter

Inherits:
Counter
  • Object
show all
Defined in:
lib/gracefully/mutex_based_synchronized_counter.rb

Overview

The counter equipped with the possibly easiest kind of synchronization.

Instance Method Summary collapse

Constructor Details

#initialize(counter) ⇒ MutexBasedSynchronizedCounter

Returns a new instance of MutexBasedSynchronizedCounter.

Parameters:



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

#countObject



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