Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Creates threads which can run in a loop, and be controlled by start, stop, or kill from the thread itself
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
MIT-LICENSE
README
README.md
gem-public_cert.pem
xthreads.gemspec

README.md

Introducing the Run Every gem

require 'run_every'

RunEvery.four.seconds {puts 'hello'}
#=> hello
#=> hello
#=> hello

RunEvery.new(seconds: 4) {puts 'hi'}
#=> hi
#=> hi
#=> hi

#RunEvery.two.minutes {puts 'hello'}

The Run Every gem is a simple timer with a code block. The interval can be set in seconds or minutes either using method chaining or through a hash passed into initialize(). The chaining method intervals include: one, two, three, four, five, ten, fifteen, twenty, twentyfive, thirty, forty, fifty.

Resources

update: 3-Apr-2011 @ 7:41pm

a = '12'
RunEvery.new(seconds: 6) do 
  if a == '12' then
    puts '..'
  elsif a == '1' then
    puts 'we have a winner'
    Thread.stop
  else
    puts 'nothing to see here'
  end
end

a = 1
#=> we have a winner

2 things worth noting: 1) variable scope can extend to outside the block. 2) The thread can be stopped from within the block using Thread.stop

every gem ruby simple timer

Something went wrong with that request. Please try again.