Guest User

Timer

a guest
Jul 16th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.50 KB | None | 0 0
  1. Error Im getting.. in 'sleep' : time interval must be positive <Argument Error>
  2.  
  3. def time_block
  4.    start_time = Time.now
  5.    yield
  6.    data = Time.now - start_time
  7.    #return Time.now - start_time
  8.    return data.abs
  9. end
  10.  
  11. def repeat_every(seconds)
  12.    while true do
  13.      # begin   
  14.      time = sleep( seconds - time_block { yield } ) # again ignoring time > seconds
  15.      puts time
  16.      #rescue
  17.      #puts "Time interval was not positive"
  18.      #end #begin
  19.    end
  20. end
  21.  
  22. repeat_every(8.0) do
  23.    checkMail
  24. end
Advertisement
Add Comment
Please, Sign In to add comment