开发者

Ruby timeout a block of code after n *milli* seconds

开发者 https://www.devze.com 2022-12-18 02:43 出处:网络
In Ruby, I need to time out the execution of a block of code after n milli seconds. I know that the Ruby Timeout lib开发者_StackOverflow中文版rary supports timeouts in seconds:

In Ruby, I need to time out the execution of a block of code after n milli seconds. I know that the Ruby Timeout lib开发者_StackOverflow中文版rary supports timeouts in seconds:

http://ruby-doc.org/stdlib/libdoc/timeout/rdoc/index.html

Is this possible?


Just use a decimal value for the timeout. Example for n milliseconds:

Timeout::timeout(n / 1000.0) { sleep(100) }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号