我怎麼能寫,我的代碼睡眠不是例如5秒,但直到在機器上的某個時間到達。紅寶石睡眠到特定時間
並非如此:
sleep(5)
但類似:
now = DateTime.Now
while now != "14:40:03"
sleep(0.5)
end
它是如何正確的呢?
我怎麼能寫,我的代碼睡眠不是例如5秒,但直到在機器上的某個時間到達。紅寶石睡眠到特定時間
並非如此:
sleep(5)
但類似:
now = DateTime.Now
while now != "14:40:03"
sleep(0.5)
end
它是如何正確的呢?
require "time"
sleep(Time.parse("14:40:03") - Time.now)
或者使用魯弗斯調度
https://github.com/jmettraux/rufus-scheduler
從OpenWFEru/RUOTE項目。
require 'rubygems'
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
scheduler.in '20m' do
#do something
end
這提供了一個真正的被動等待,空載。
我之前嘗試過,但:http://stackoverflow.com/questions/19447467/rufus-scheduler-time-format – brabertaser19
我相信你想在特定的時間做一些任務嗎?什麼是用例?爲什麼不使用cron作業? – Lavixu