Class: Cabin::Metrics::Timer::TimerContext

Inherits:
Object
  • Object
show all
Defined in:
lib/cabin/metrics/timer.rb

Overview

def time_block

Instance Method Summary collapse

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

#stopObject



34
35
36
37
# File 'lib/cabin/metrics/timer.rb', line 34

def stop
  duration = Time.now - @start
  @callback.call(duration)
end