English 中文(简体)
活动Machine:
原标题:EventMachine::HttpRequest and Keep-alive connection

我用以下代码来管理吉大港山区的申请,但第二项请求(req2)总是回退。

我在这里没有明显的东西?

request_options = {
  :body => " ",
  :keepalive => true,
  :head => {
     content-type  =>  application/json ,
     accept  =>  application/json ,
     Accept-Encoding  =>  gzip,deflate,sdch 
  }
}

EM.run do
  request_options[:path] =  /default/path 

  conn = EM::HttpRequest.new  https://www.example.com 

  req1 = conn.post request_options
  req1.errback { p  Uh, oh ; EM.stop }
  req1.callback do
    doc = JSON.parse req1.response

    # do stuff with doc

    request_options[:body] =  post-data 
    request_options[:path] =  /new/path 

    req2 = conn.post request_options
    req2.errback { p  Uh, oh ; EM.stop }
    req2.callback do
       puts req2.response
       EM.stop
    end
  end
end
最佳回答

我通过使用<>中程>-Synchrony解决了我的问题。

gem install em-synchrony

随着这一轮椅的安装,我可以按照我的期望使用以下代码来使该守则发挥作用。

request_options = {
  :body => " ",
  :keepalive => true,
  :head => {
     content-type  =>  application/json ,
     accept  =>  application/json ,
     Accept-Encoding  =>  gzip,deflate,sdch 
  }
}

EM.synchrony do
  request_options[:path] =  /default/path 

  conn = EM::HttpRequest.new  https://www.example.com 

  req1 = conn.post request_options
  doc = JSON.parse req1.response

  # do stuff with doc

  request_options[:body] =  post-data 
  request_options[:path] =  /new/path 

  req2 = conn.post request_options
  puts req2.response

  EM.stop
end

我猜想一下,我只是混淆了他们走的路。 运行确实是非同步要求,也是零。

问题回答

你可以在回击中使用同样的电击标。

确保创建新的<条码>。 EM:HttpRequest.new https://www.example.com。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签