open-uriを使用して複数の同時接続を開く方法について知りたいですか?私はスレッドや繊維をいくつか使用する必要があると思うが、私はよくわからない。Ruby(およびopen-uri)を使用して並列で配列内のアイテムを処理する方法
コード例:あなたがこれを行うことができますpeach
(https://rubygems.org/gems/peach)と呼ばれる宝石があり
def get_doc(url)
begin
Nokogiri::HTML(open(url).read)
rescue Exception => ex
puts "Failed at #{Time.now}"
puts "Error: #{ex}"
end
end
array_of_urls_to_process = [......]
# How can I iterate over items in the array in parallel (instead of one at a time?)
array_of_urls_to_process.each do |url|
x = get_doc(url)
do_something(x)
end
宝石はjrubyのみです –