Created
April 6, 2012 17:29
-
-
Save eric/2321514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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