Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 对于相同的请求,em同步不是异步的_Ruby On Rails_Ruby_Asynchronous_Thin_Eventmachine - Fatal编程技术网

Ruby on rails 对于相同的请求,em同步不是异步的

Ruby on rails 对于相同的请求,em同步不是异步的,ruby-on-rails,ruby,asynchronous,thin,eventmachine,Ruby On Rails,Ruby,Asynchronous,Thin,Eventmachine,在rails应用程序中,我有一个异步方法,它只在请求不同时异步工作 在我的控制器中,我有以下方法: require "em-synchrony/em-http" def test EventMachine.synchrony do page = EventMachine::HttpRequest.new("http://127.0.0.1:8081/").get render :json => {result: page.response}

在rails应用程序中,我有一个异步方法,它只在请求不同时异步工作

在我的控制器中,我有以下方法:

require "em-synchrony/em-http"
def test

    EventMachine.synchrony do
      page = EventMachine::HttpRequest.new("http://127.0.0.1:8081/").get

      render :json => {result: page.response}
      request.env['async.callback'].call(response)
    end
    throw :async
end
在我的页面中,我这样调用此方法:

//Not asynchronous. :(
//The second request takes twice more time than the first one
$.get("/test");
$.get("/test");
但是,要使调用异步,我需要请求不同,如下所示:

//Asynchronous. :D
$.get("/test?a");
$.get("/test?b");
为什么??
我希望我的代码总是异步的。即使是相同的请求。仅供参考,我正在使用服务器瘦

我发现您的问题非常有趣,因为我将实现我的第一个基于Reactor模式的web服务器,当然我还通过了em syncrony

您是否也尝试过使用
aget
而不是
get

page = EventMachine::HttpRequest.new("http://127.0.0.1:8081/").aget
如果有什么不同,请告诉我:)