我最近从mongrel切换到thin时升级到rails 3.在切换之前,我们一直使用EventMachine没有任何问题。切换到精简之后,无论何时调用EventMachine,服务器都会弹出并说我们返回的变量为零。使用EventMachine和Thin
从我所了解的薄利用EventMachine这可能会导致与Mongrel一起使用的实现冲突。我还没有用过很多EventMachine,但似乎需要在另一个实例中运行EventMachine,以将它与正在使用的EventMachine分开。我在正确的轨道上吗?我如何才能在Thin's EventMachine之外独立运行它?
这里是EventMachine的一个片段,我们目前已经实现
def connect
EventMachine.run {
args, options = {
:query => @options[:query],
:head => @options[:headers]
}, {
:connect_timeout => @options[:timeout],
:inactivity_timeout => @options[:timeout]
}
args[:body] = @options[:data] if allow_body?
args[:redirects] = @options[:redirects] if @options[:redirects]
http = EventMachine::HttpRequest.new(@uri, options).send(@options[:method], args)
http.errback {
@response = HttpConnection::Response.new(http, false, @options[:logger])
EventMachine.stop
}
http.callback {
@response = HttpConnection::Response.new(http, true, @options[:logger])
EventMachine.stop
}
}
return @response
end
你说得对,Thin已经提供了一个EM反应器。而且EM.stop会发出信号减弱以停止!我决定彻底放弃这个EM实现,因为它看起来不正确。我会看看使用Sinatra和异步插件。谢谢丹 –