English 中文(简体)
4. 达格·哈马舍尔德图书馆同时提出请求
原标题:Ruby library to make multiple HTTP requests simultaneously

I m 寻找一个替代的Rub HTTP图书馆,使多功能的吉大港定居人士协会同时使用,并比核心网更好地运作:吉大港定居人士协会图书馆。

最佳回答

或许你正在寻找典型鞋子。

典型鞋类同时处理吉大港山区的申请,同时明确概括处理逻辑

https://github.com/typhoeus/typhoeus

问题回答

为什么需要一个网络图书馆来处理平行问题? 这正是什么样子。

require "open-uri"

fetcher = lambda do |uri|
  puts "Started fetching #{uri}"
  puts open(uri).read
  puts "Stopped fetching #{uri}"
end

thread1 = Thread.new("http://localhost:9292", &fetcher)
thread2 = Thread.new("http://localhost:9293", &fetcher)

thread1.join
thread2.join

Also, I don t understand what do you mean by "performs better". Core libraries are usually good enough to be in the core. Do you have any problems with Net::HTTP?

你们可以使用平行的宝石,应该与任何Ruby HTTP图书馆合作。

如果不能更好地进行打字,英国广播公司可以使用突发事件+胚胎。 发出多重要求就是一个例子。

require  eventmachine 
require  em-http 

EventMachine.run {
  multi = EventMachine::MultiRequest.new

  reqs = [
     http://google.com/ ,
     http://google.ca:81/ 
  ]

  reqs.each_with_index do |url, idx|
    http = EventMachine::HttpRequest.new(url, :connect_timeout => 1)
    req = http.get
    multi.add idx, req
  end

  multi.callback  do
    p multi.responses[:callback].size
    p multi.responses[:errback].size
    EventMachine.stop
  end
}

https://github.com/igrigorik/em-http-request”rel=“nofollow>https://github.com/igrigorik/em-http-request





相关问题
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 ...

热门标签