From f385ed423e11ad40822f688bc592eaa78efa5b34 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 9 Jan 2017 18:59:00 +0000 Subject: eventmachine: wait for deferred actions to finish 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 on the mailing list for bringing this up: https://bogomips.org/rainbows-public/CAKwvcL-VH3we4qA1pkNAstTmWvqNA=Rir2N_YiWztV_qbaLQvA@mail.gmail.com/ --- lib/rainbows/event_machine.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/rainbows/event_machine.rb') 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| -- cgit v1.2.3-24-ge0c7