summary refs log tree commit homepage
path: root/lib/rainbows/queue_pool.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-03-22 11:08:31 -0700
committerEric Wong <normalperson@yhbt.net>2011-03-22 18:09:07 +0000
commit777beb3e27785d2da2865cb5fc0d43f1c158cb5e (patch)
treec52e5d9777c544c2b6df3f9e14c9fa60c54b3030 /lib/rainbows/queue_pool.rb
parentdd6d5168e4f3dcb4555264265a05e5b61273893d (diff)
Diffstat (limited to 'lib/rainbows/queue_pool.rb')
-rw-r--r--lib/rainbows/queue_pool.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/rainbows/queue_pool.rb b/lib/rainbows/queue_pool.rb
index ce888d8..06f7c40 100644
--- a/lib/rainbows/queue_pool.rb
+++ b/lib/rainbows/queue_pool.rb
@@ -5,24 +5,26 @@ require 'thread'
 # Thread pool class based on pulling off a single Ruby Queue.
 # This is NOT used for the ThreadPool class, since that class does not
 # need a userspace Queue.
-class Rainbows::QueuePool < Struct.new(:queue, :threads)
+class Rainbows::QueuePool
+  attr_reader :queue
+
   def initialize(size = 20)
     q = Queue.new
-    self.threads = (1..size).map do
+    @threads = (1..size).map do
       Thread.new do
         while job = q.shift
           yield job
         end
       end
     end
-    self.queue = q
+    @queue = q
   end
 
   def quit!
-    threads.each { |_| queue << nil }
-    threads.delete_if do |t|
+    @threads.each { |_| @queue << nil }
+    @threads.delete_if do |t|
       Rainbows.tick
       t.alive? ? t.join(0.01) : true
-    end until threads.empty?
+    end until @threads.empty?
   end
 end