From da38667dfe111c47cc9a0fc1f40a542bd1148434 Mon Sep 17 00:00:00 2001 From: tazro inutano ohta Date: Tue, 4 Feb 2014 17:38:21 +0900 Subject: [PATCH] threads for the list of large amount of values --- sync_and_unzip.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sync_and_unzip.rb b/sync_and_unzip.rb index ac48e4a..a04eee2 100644 --- a/sync_and_unzip.rb +++ b/sync_and_unzip.rb @@ -1,4 +1,5 @@ # :) +# using Enumerable#lazy, only for Ruby 2.0 require "rake" @@ -30,15 +31,15 @@ def get_files(sym, dir) end def unzip_all - threads = [] - @unziplist.each do |fastqc_id| - th = Thread.new do - unzip(fastqc_id) - end - threads << th + threads = @unziplist.lazy.map{|id| unzip_task(id) } + threads.each_slice(12).each do |group| + group.each{|t| t.join } end - threads.each do |th| - th.join + end + + def unzip_task(fastqc_id) + Thread.new do + unzip(fastqc_id) end end