Created
October 23, 2012 08:27
-
-
Save miminashi/3937632 to your computer and use it in GitHub Desktop.
タイマーのサンプル
This file contains 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
# coding:utf-8 | |
INTERVAL = 1 | |
next_exec = Time.now | |
loop do | |
if Time.now > next_exec | |
# ここから | |
now = Time.now | |
puts "スケジュールされた時刻: #{next_exec.sec} #{next_exec.nsec}" | |
puts "実際の時刻: #{now.sec} #{now.nsec}" | |
puts | |
# ここまでが実際の処理内容 | |
next_exec = next_exec + INTERVAL | |
else | |
sleep(0.001) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment