Created
February 18, 2011 15:25
-
-
Save blasterpal/833810 to your computer and use it in GitHub Desktop.
Nested System Timer Test
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 characters
| require 'rubygems' | |
| require 'system_timer' | |
| class JobWrapper | |
| attr_accessor :timeout, :job, :name | |
| # slowjob1 = SlowJob.new(15,'slowjob1') | |
| # wrapper = JobWrapper.new(10,slowjob1) | |
| # wrapper2 = JobWrapper.new(5,wrapper) | |
| def initialize(timeout,job) | |
| @timeout = timeout | |
| @job = job | |
| @name = job.to_s | |
| end | |
| def run() | |
| begin | |
| SystemTimer.timeout(timeout) do | |
| #do_something_that_could_take_a_long_time | |
| job.run | |
| end | |
| rescue Timeout::Error | |
| puts "job #{job.name} has timed-out" | |
| end | |
| end | |
| end | |
| class SlowJob | |
| attr_accessor :length,:name | |
| def initialize(length,name) | |
| @length = length | |
| @name = name | |
| end | |
| def run | |
| length.times do | |
| putc '.' | |
| sleep 1 | |
| end | |
| puts '' | |
| puts 'done with slow job' | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment