From a310302708faa19042282e94525544cfbb23eba5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 27 Dec 2010 02:36:58 +0000 Subject: writer_thread_spawn: factor out Client.quit Self-documenting code is easier to follow --- lib/rainbows/writer_thread_spawn.rb | 8 ++------ lib/rainbows/writer_thread_spawn/client.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/rainbows/writer_thread_spawn.rb b/lib/rainbows/writer_thread_spawn.rb index a11e82c..0e7d1a7 100644 --- a/lib/rainbows/writer_thread_spawn.rb +++ b/lib/rainbows/writer_thread_spawn.rb @@ -32,12 +32,8 @@ module Rainbows::WriterThreadSpawn def worker_loop(worker) # :nodoc: Client.const_set(:MAX, worker_connections) - super(worker) # accept loop from Unicorn - Client::CUR.delete_if do |t,q| - q << nil - G.tick - t.alive? ? t.join(0.01) : true - end until Client::CUR.empty? + super # accept loop from Unicorn + Client.quit end # :startdoc: end diff --git a/lib/rainbows/writer_thread_spawn/client.rb b/lib/rainbows/writer_thread_spawn/client.rb index 4341b9a..f9c373e 100644 --- a/lib/rainbows/writer_thread_spawn/client.rb +++ b/lib/rainbows/writer_thread_spawn/client.rb @@ -7,6 +7,15 @@ class Rainbows::WriterThreadSpawn::Client < Struct.new(:to_io, :q, :thr) CUR = {} # :nodoc: + def self.quit + g = Rainbows::G + CUR.delete_if do |t,q| + q << nil + g.tick + t.alive? ? t.join(0.01) : true + end until CUR.empty? + end + def queue_writer # not using Thread.pass here because that spins the CPU during # I/O wait and will eat cycles from other worker processes. -- cgit v1.2.3-24-ge0c7