簡體   English   中英

em-synchrony對於相同的請求不是異步的

[英]em-synchrony not asynchronous for identical requests

在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");

為什么? 我希望我的代碼總是異步的。 即使是相同的請求。 僅供參考,我正在使用服務器Thin

我發現您的問題真的很有趣,因為我將實現我的第一個基於Reactor模式的Web服務器,當然我也經歷了em-syncrony。

您是否嘗試過使用aget代替get

page = EventMachine::HttpRequest.new("http://127.0.0.1:8081/").aget

讓我知道是否有任何不同:)!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM