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

前端 未结 5 1626
灰色年华
灰色年华 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条回答
  •  自闭症患者
    2021-02-20 13:24

    A simple method using threads:

    threads = []
    
    [1, 2, 3].each do |i|
      threads << Thread.new { puts i }
    end
    
    threads.each(&:join)
    

提交回复
热议问题