Sha256: 0f65484fb3d4acac32c4e7b017d99e71fd0bf0f98606728fbf0212b257ced795

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 KB

Contents

# -*- encoding: binary -*-

# 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.
#
# 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 # :nodoc:

  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
    @app = app
  end

  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)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rainbows-4.7.0 lib/rainbows/event_machine/try_defer.rb
rainbows-4.6.2 lib/rainbows/event_machine/try_defer.rb
rainbows-4.6.1 lib/rainbows/event_machine/try_defer.rb
rainbows-4.6.0.4.g4108 lib/rainbows/event_machine/try_defer.rb
rainbows-4.6.0 lib/rainbows/event_machine/try_defer.rb
rainbows-4.5.0 lib/rainbows/event_machine/try_defer.rb
rainbows-4.4.3 lib/rainbows/event_machine/try_defer.rb
rainbows-4.4.2 lib/rainbows/event_machine/try_defer.rb
rainbows-4.4.1.1.gd5c8c lib/rainbows/event_machine/try_defer.rb
rainbows-4.4.1 lib/rainbows/event_machine/try_defer.rb
rainbows-4.4.0 lib/rainbows/event_machine/try_defer.rb
rainbows-4.3.1 lib/rainbows/event_machine/try_defer.rb
rainbows-4.3.0 lib/rainbows/event_machine/try_defer.rb
rainbows-4.2.0 lib/rainbows/event_machine/try_defer.rb
rainbows-4.1.0 lib/rainbows/event_machine/try_defer.rb
rainbows-4.0.0 lib/rainbows/event_machine/try_defer.rb
rainbows-3.4.0 lib/rainbows/event_machine/try_defer.rb