Created
March 22, 2012 16:36
-
-
Save tobi/2159436 to your computer and use it in GitHub Desktop.
Revisions
-
Tobias Lütke created this gist
Mar 22, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ trap("INT") { $done = true } class Forever def every(timespan, &block) @threads ||= [] thread = Thread.new do last_run = 0 while !$done now = Time.now.to_i if now - last_run > timespan block.call last_run = now end sleep 1 end end @threads.push(thread) end def run @threads.collect(&:join) end end require 'rubygems' require 'active_support/all' forever = Forever.new forever.every 5.seconds do puts 'still running' end forever.run