在 Ruby 中高效地在 x 秒内执行任务

发布于 2024-12-21 09:04:34 字数 98 浏览 1 评论 0原文

在我的 Sinatra 应用程序中,我希望当用户访问特定 URL 时调用一个方法,然后在 x 秒后(不保持 HTTP 流打开),应该调用一个不同的方法。

我该怎么做?

In my Sinatra application I'd like a method to be called when a user visits a specific URL then, x seconds later (without keeping the HTTP stream open), a different method should be called.

How should I do this?

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

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

发布评论

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

评论(1

伴我心暖 2024-12-28 09:04:34

您可以使用 Ruby 线程

second_thread = Thread.new() do
    sleep 10 # Let's only execute this after 10 seconds
    ... do processing here
end

second_thread.join()

希望有帮助!

You could use Ruby Threads:

second_thread = Thread.new() do
    sleep 10 # Let's only execute this after 10 seconds
    ... do processing here
end

second_thread.join()

Hope that helps!

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