about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/rainbows/event_machine.rb8
-rw-r--r--t/app_deferred.ru1
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index 4b852c9..b19bdec 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -209,6 +209,14 @@ module Rainbows
     # This middleware is automatically loaded by Rainbows! when using
     # EventMachine and if the app responds to the +deferred?+ method.
     class TryDefer < Struct.new(:app)
+
+      def initialize(app)
+        # the entire app becomes multithreaded, even the root (non-deferred)
+        # thread since any thread can share processes with others
+        Const::RACK_DEFAULTS['rack.multithread'] = true
+        super
+      end
+
       def call(env)
         if app.deferred?(env)
           EM.defer(proc { catch(:async) { app.call(env) } },
diff --git a/t/app_deferred.ru b/t/app_deferred.ru
index 179ac95..a70b33b 100644
--- a/t/app_deferred.ru
+++ b/t/app_deferred.ru
@@ -10,6 +10,7 @@ class DeferredApp < Struct.new(:app)
   end
 
   def call(env)
+    env["rack.multithread"] or raise RuntimeError, "rack.multithread not true"
     body = "#{Thread.current.inspect}\n"
     headers = {
       "Content-Type" => "text/plain",