Skip to content

Instantly share code, notes, and snippets.

@miminashi
Created October 23, 2012 08:27
Show Gist options
  • Save miminashi/3937632 to your computer and use it in GitHub Desktop.
Save miminashi/3937632 to your computer and use it in GitHub Desktop.
タイマーのサンプル
# 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