How to Process Items in an Array in Parallel using Ruby (and open-uri)

前端 未结 5 1547
灰色年华
灰色年华 2021-02-20 12:41

I am wondering how i can go about opening multiple concurrent connections using open-uri? i THINK I need to use threading or fibers some how but i\'m not sure.

Exampl

5条回答
  •  Happy的楠姐
    2021-02-20 13:35

    There is a gem called peach (https://rubygems.org/gems/peach) which lets you do this:

    require "peach"
    
    array_of_urls_to_process.peach do |url|
      do_something(get_doc(url))
    end
    

提交回复
热议问题