From f83fe5edb79e51616afcf2a9f991cfe153eabd48 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 20 May 2011 15:44:48 -0700 Subject: try_defer: enable documentation It should hopefully give this more visibility even though it's an internal feature. --- lib/rainbows/event_machine.rb | 4 +--- lib/rainbows/event_machine/try_defer.rb | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 025b795..fb7177b 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -32,9 +32,7 @@ EM::VERSION >= '0.12.10' or abort 'eventmachine 0.12.10 is required' # all request processing is complete. # # Merb (and other frameworks/apps) supporting +deferred?+ execution as -# documented at http://brainspl.at/articles/2008/04/18/deferred-requests-with-merb-ebb-and-thin -# will also get the ability to conditionally defer request processing -# to a separate thread. +# documented at Rainbows::EventMachine::TryDefer # # This model does not implement as streaming "rack.input" which allows # the Rack application to process data as it arrives. This means diff --git a/lib/rainbows/event_machine/try_defer.rb b/lib/rainbows/event_machine/try_defer.rb index 97e384d..615adae 100644 --- a/lib/rainbows/event_machine/try_defer.rb +++ b/lib/rainbows/event_machine/try_defer.rb @@ -1,27 +1,32 @@ # -*- encoding: binary -*- -# :enddoc: # Middleware that will run the app dispatch in a separate thread. # This middleware is automatically loaded by Rainbows! when using # EventMachine and if the app responds to the +deferred?+ method. -class Rainbows::EventMachine::TryDefer < Struct.new(:app) +# +# Use EM.threadpool_size in your \Rainbows! config file to control +# the number of threads used by EventMachine. +# +# See http://brainspl.at/articles/2008/04/18/deferred-requests-with-merb-ebb-and-thin +# for more information. +class Rainbows::EventMachine::TryDefer # shortcuts - ASYNC_CALLBACK = Rainbows::EvCore::ASYNC_CALLBACK + ASYNC_CALLBACK = Rainbows::EvCore::ASYNC_CALLBACK # :nodoc: - def initialize(app) + def initialize(app) # :nodoc: # the entire app becomes multithreaded, even the root (non-deferred) # thread since any thread can share processes with others Rainbows::Const::RACK_DEFAULTS['rack.multithread'] = true - super + @app = app end - def call(env) - if app.deferred?(env) - EM.defer(proc { catch(:async) { app.call(env) } }, env[ASYNC_CALLBACK]) + def call(env) # :nodoc: + if @app.deferred?(env) + EM.defer(proc { catch(:async) { @app.call(env) } }, env[ASYNC_CALLBACK]) # all of the async/deferred stuff breaks Rack::Lint :< nil else - app.call(env) + @app.call(env) end end end -- cgit v1.2.3-24-ge0c7