为什么没有Ruby超时引发错误?

时间:2015-10-30 15:53:25

标签: ruby timeout

为什么这段代码没有引发错误?

require 'net/ping'
host = Net::Ping::External.new('1.1.1.1')

Timeout.timeout(3) do
  until host.ping?
    sleep(1)
    host = Net::Ping::External.new('1.1.1.1')
  end
end

此示例引发了错误:

require 'net/ping'

Timeout.timeout(3) do
  until false
    sleep(4)
  end
end

ruby​​-2.0.0-p594 [x86_64]。也许这是ruby版本的问题?因为使用ruby-2.1.3 [x86_64]一切都还可以。

0 个答案:

没有答案