Class: Cabin::Metrics::Counter
- Inherits:
-
Object
- Object
- Cabin::Metrics::Counter
- Defined in:
- lib/cabin/metrics/counter.rb
Instance Method Summary collapse
-
#decr ⇒ Object
decrement this counter.
-
#incr ⇒ Object
increment this counter.
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #value ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
9 10 11 12 |
# File 'lib/cabin/metrics/counter.rb', line 9 def initialize @value = 0 @lock = Mutex.new end |
Instance Method Details
#decr ⇒ Object
decrement this counter
20 21 22 |
# File 'lib/cabin/metrics/counter.rb', line 20 def decr @lock.synchronize { @value -= 1 } end |
#incr ⇒ Object
increment this counter
15 16 17 |
# File 'lib/cabin/metrics/counter.rb', line 15 def incr @lock.synchronize { @value += 1 } end |
#value ⇒ Object
26 27 28 |
# File 'lib/cabin/metrics/counter.rb', line 26 def value return @lock.synchronize { @value } end |