Ruby 在 n *毫秒* 秒后使代码块超时

发布于 2024-08-19 08:59:38 字数 249 浏览 2 评论 0原文

在 Ruby 中,我需要在 n milli 秒后超时执行一段代码。我知道 Ruby Timeout 库支持以秒为单位的超时:

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

这可能吗?

In Ruby, I need to time out the execution of a block of code after n milli seconds. I know that the Ruby Timeout library supports timeouts in seconds:

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

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蔚蓝源自深海 2024-08-26 08:59:38

只需使用十进制值作为超时值。 n 毫秒的示例:

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

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

Timeout::timeout(n / 1000.0) { sleep(100) }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文