class Cabin::Timer

A simple timer class for timing events like a stop watch. Normally you don't invoke this yourself, but you are welcome to do so.

See also: Cabin::Channel#time

Public Class Methods

new(&block) click to toggle source
# File lib/cabin/timer.rb, line 8
def initialize(&block)
  @start = Time.now
  @callback = block if block_given?
end

Public Instance Methods

stop() click to toggle source

Stop the clock and call the callback with the duration. Also returns the duration of this timer.

# File lib/cabin/timer.rb, line 15
def stop
  duration = Time.now - @start
  @callback.call(duration) if @callback
  return duration
end