about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-20 14:22:37 -0700
committerEric Wong <normalperson@yhbt.net>2011-05-20 14:23:57 -0700
commit5d5033afa9052dc0d60e743f07bc694f008182b3 (patch)
tree88a42d045ac4fc87f5bb69482d4a4ddaf4360d00
parentbba079d8a605b546bc262e80234c3c233a386e44 (diff)
downloadrainbows-5d5033afa9052dc0d60e743f07bc694f008182b3.tar.gz
Since it's cheap to maintain keepalive clients with EM, we need
a way of disconnecting them in a timely fashion on rare SIGQUIT
events.
-rw-r--r--lib/rainbows/event_machine.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index b136518..025b795 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -74,11 +74,11 @@ module Rainbows::EventMachine
       conns = EM.instance_variable_get(:@conns) or
         raise RuntimeError, "EM @conns instance variable not accessible!"
       Rainbows::EventMachine::Server.const_set(:CUR, conns)
+      Rainbows.at_quit do
+        EM.next_tick { conns.each_value { |c| client_class === c and c.quit } }
+      end
       EM.add_periodic_timer(1) do
-        unless Rainbows.tick
-          conns.each_value { |c| client_class === c and c.quit }
-          EM.stop if conns.empty? && EM.reactor_running?
-        end
+        EM.stop if ! Rainbows.tick && conns.empty? && EM.reactor_running?
       end
       LISTENERS.map! do |s|
         EM.watch(s, Rainbows::EventMachine::Server) do |c|