Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Helper library to provide callbacks for various intervals such as every n items.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
README.textile
Rakefile
cadence.gemspec

README.textile

Cadence

Track counts and compute rate of iteration. Set up callbacks for various
intervals such as every n increments or every n ticks.

Sample

require 'lib/cadence'

data = (1..100).to_a

computer = Cadence::Computer.new do |c|
  c.every 5 do
    p [:every, 5, n]
  end
  
  c.for(:tens).every do
    p [:tens, :every, n]
  end
  
  c.twenties.every 2 do
    p [:twenties, :every, 2, n]
  end
  
  c.ticks 1 do
    p [:tock, n, timestamp]
  end
end

computer.start do |c|
  data.each do |n|
    c.next
    c.tens.next if n % 10 == 0
    p [:n, n]
    sleep 0.02
  end
end

License

MIT

Copyright

Copyright © 2010 Matt Todd.

Something went wrong with that request. Please try again.