Skip to content

Instantly share code, notes, and snippets.

@eric
Created April 6, 2012 17:29
Show Gist options
  • Save eric/2321514 to your computer and use it in GitHub Desktop.
Save eric/2321514 to your computer and use it in GitHub Desktop.
class MultiTimer
def initialize(*timers)
@timers = []
add_timer(*timers)
end
def time(callable = nil, &block)
callable ||= block
context = Metriks::Timer::Context.new(self)
if callable.nil?
return context
end
begin
return callable.call
ensure
context.stop
end
end
def update(duration)
@timers.each { |t| t.update(duration) }
end
def <<(*timers)
add_timer(*timers)
end
def add_timer(*timers)
timers.flatten.each do |timer|
if timer.is_a?(String)
@timers << Metriks.timer(timer)
else
@timers << timer
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment