Class: Cabin::Metrics::Timer::TimerContext
- Inherits:
-
Object
- Object
- Cabin::Metrics::Timer::TimerContext
- Defined in:
- lib/cabin/metrics/timer.rb
Overview
def time_block
Instance Method Summary collapse
-
#initialize(&stop_callback) ⇒ TimerContext
constructor
A new instance of TimerContext.
- #stop ⇒ Object
Constructor Details
#initialize(&stop_callback) ⇒ TimerContext
Returns a new instance of TimerContext.
28 29 30 31 |
# File 'lib/cabin/metrics/timer.rb', line 28 def initialize(&stop_callback) @start = Time.now @callback = stop_callback end |
Instance Method Details
#stop ⇒ Object
34 35 36 37 |
# File 'lib/cabin/metrics/timer.rb', line 34 def stop duration = Time.now - @start @callback.call(duration) end |