diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-05-20 15:44:48 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-05-21 01:38:36 +0000 |
commit | f83fe5edb79e51616afcf2a9f991cfe153eabd48 (patch) | |
tree | 1b92ff83eca2ca26c2c4830c2ec222fdecf8ebd5 /lib | |
parent | 0b9b4edc63c0021e567c68137e1ee7f9e99ddcc5 (diff) | |
download | rainbows-f83fe5edb79e51616afcf2a9f991cfe153eabd48.tar.gz |
It should hopefully give this more visibility even though it's an internal feature.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rainbows/event_machine.rb | 4 | ||||
-rw-r--r-- | 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 |