可以在 Thin web 应用程序中使用 EM 调用吗?
是否可以在 Thin 内部使用 EventMachine 调用而无需额外初始化?
目前,我有一个由 Thin 运行的 Sinatra 应用程序(作为服务运行)。当我尝试使用 EventMachine.connect_unix_domain
时,我得到 eventmachine notinitialed
...即使 Thin(大概还有 EventMachine)正在运行。
class App < Sinatra::Base
$sock = EventMachine.connect_unix_domain("/tmp/appsock.sock")
# import all routes
Dir.glob("controllers/*.rb").each { |r| require_relative r }
end
Is it possible to use EventMachine calls inside Thin without extra initialization?
Currently, I have a Sinatra app run by Thin (which is running as a service). When I try to use EventMachine.connect_unix_domain
, I get eventmachine not initialized
... even though Thin (and presumably EventMachine) is running.
class App < Sinatra::Base
$sock = EventMachine.connect_unix_domain("/tmp/appsock.sock")
# import all routes
Dir.glob("controllers/*.rb").each { |r| require_relative r }
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测(抱歉,这个盒子上没有安装 em)是因为在加载类时将评估代码。此时,thin 可能尚未设置,EM 可能尚未初始化。
您可以尝试将 $sock = ... 调用包装在 EM.next_tick {} 中,这应该延迟执行,直到 EM 实际启动。
我相信,如果没记错的话,您可以在 EM 实际初始化之前向 next_tick 添加内容。
My guess (sorry, don't have em installed on this box) is that the issue is because the code will be evaluated when the class is loaded. At that point, thin probably isn't setup and EM probably isn't initialized.
You could try wrapping the $sock = ... call in an EM.next_tick {} which should delay the execution until EM has actually started.
I believe, if memory serves, you can add stuff to next_tick before EM is actually initialized.