about summary refs log tree commit homepage
path: root/lib/rainbows
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-09 18:59:00 +0000
committerEric Wong <e@80x24.org>2017-01-09 18:59:00 +0000
commitf385ed423e11ad40822f688bc592eaa78efa5b34 (patch)
tree1cc73c8b3c1ebba45c2ed23d27c32467e778fe4b /lib/rainbows
parent28194bd423ee559a2693459fcceb24ea1200863b (diff)
downloadrainbows-f385ed423e11ad40822f688bc592eaa78efa5b34.tar.gz
Since EventMachine 1.0.0 in 2012, the EM.defers_finish? API
exists to check for the existence of deferred actions.
Support it if it exists in the running version of EM and
update the note in our SIGNALS document.

Thanks to <alex0375@gmail.com> on the mailing list for bringing
this up:
https://bogomips.org/rainbows-public/CAKwvcL-VH3we4qA1pkNAstTmWvqNA=Rir2N_YiWztV_qbaLQvA@mail.gmail.com/
Diffstat (limited to 'lib/rainbows')
-rw-r--r--lib/rainbows/event_machine.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index b326e26..896fdac 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -65,6 +65,11 @@ module Rainbows::EventMachine
     end
   end
 
+  def defers_finished?
+    # EventMachine 1.0.0+ has defers_finished?
+    EM.respond_to?(:defers_finished?) ? EM.defers_finished? : true
+  end
+
   # runs inside each forked worker, this sits around and waits
   # for connections and doesn't die until the parent dies (or is
   # given a INT, QUIT, or TERM signal)
@@ -101,7 +106,10 @@ module Rainbows::EventMachine
         end
       end
       EM.add_periodic_timer(1) do
-        EM.stop if ! Rainbows.tick && conns.empty? && EM.reactor_running?
+        if ! Rainbows.tick && conns.empty? && defers_finished? &&
+            EM.reactor_running?
+          EM.stop
+        end
       end
       LISTENERS.map! do |s|
         EM.watch(s, Rainbows::EventMachine::Server) do |c|