How to install SystemTimer on 1.9.2?

点点圈 提交于 2019-12-04 23:25:06

As far as I know, SystemTimer isn't relevant for ruby 1.9 and shouldn't use with this version.

"Using this gem in Ruby 1.9 is useless and does not make any sense! System Timer is trying to work around some limitation of the "green thread" model used in Ruby 1.8 (MRI). See http://ph7spot.com/musings/system-timer for more details."

A drop-in replacement for SystemTimer is timeout.rb from Ruby core. No need for any 3rd party gems.

Ruby 1.8:

require 'system_timer'

SystemTimer.timeout_after(5.minutes, MyException) do
  # your job here
end

Ruby 1.9:

require 'timeout'

Timeout.timeout(5.minutes, MyException) do
  # your job here
end

To install system timer use this command in Terminal:

sudo gem install system_timer
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!