From 53bac4f65d9430495c8043b239cc936012ea7a8d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 6 Feb 2011 06:19:09 +0000 Subject: minimize &block usage for yield No need to allocate a proc every time when we can just yield much more efficiently. --- lib/rainbows/queue_pool.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/rainbows/queue_pool.rb') diff --git a/lib/rainbows/queue_pool.rb b/lib/rainbows/queue_pool.rb index 99cb9db..ce888d8 100644 --- a/lib/rainbows/queue_pool.rb +++ b/lib/rainbows/queue_pool.rb @@ -6,12 +6,12 @@ require 'thread' # This is NOT used for the ThreadPool class, since that class does not # need a userspace Queue. class Rainbows::QueuePool < Struct.new(:queue, :threads) - def initialize(size = 20, &block) + def initialize(size = 20) q = Queue.new self.threads = (1..size).map do Thread.new do while job = q.shift - block.call(job) + yield job end end end -- cgit v1.2.3-24-ge0c7