来自 金沙js77888 2019-06-19 04:50 的文章
当前位置: 金沙js77888 > 金沙js77888 > 正文

Running a Code Block Periodically

def every_n_seconds(n)
  loop do
    before = Time.now
    yield
    interval = n-(Time.now-before)
    sleep(interval) if interval > 0
  end
end

every_n_seconds(5) do
 puts '#{Time.now.strftime('%X')}... beep!'
end

本文由金沙js77888发布于金沙js77888,转载请注明出处:Running a Code Block Periodically

关键词: 金沙js7799 Ruby Method