Skip to content

Commit

Permalink
Disable Rack::FiberPool
Browse files Browse the repository at this point in the history
  • Loading branch information
frodenas committed Dec 17, 2012
1 parent 9dd6510 commit 8e56f20
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -28,6 +28,7 @@ If you plan to deploy this app to a production environment:
* Change the secret token at /config/initializers/secret_token.rb
* Remove "= render "layouts/forkapp"" at /app/views/layouts/application.html.haml
* precompile the assets -> RAILS_ENV=production rake assets:precompile
* enable "config.middleware" option at /config/application.rb to enable async http calls

Testing
-------
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -40,7 +40,7 @@ def cloudfoundry_client(cf_target_url, cf_auth_token = nil)
end

def which_faraday_adapter?
if defined?(EM::Synchrony) && EM.reactor_running?
if Utils::ModuleLoaded.synchrony? && Utils::ModuleLoaded.fiberpool?
:em_synchrony
else
:net_http
Expand Down
3 changes: 2 additions & 1 deletion config/application.rb
Expand Up @@ -65,7 +65,8 @@ class Application < Rails::Application
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

# Enable this option if you want async http calls
# Place the FiberPool early in the pipeline (you can see your app's current pipeline using `rake middleware`)
config.middleware.insert_before Rails::Rack::Logger, Rack::FiberPool
#config.middleware.insert_before Rails::Rack::Logger, Rack::FiberPool
end
end
14 changes: 12 additions & 2 deletions lib/utils.rb
@@ -1,4 +1,14 @@
module Utils
module ModuleLoaded
def self.synchrony?
defined?(EM::Synchrony) && EM.reactor_running?
end

def self.fiberpool?
CfConsole::Application.config.middleware.middlewares.include?(Rack::FiberPool)
end
end

module EMDeferredBlock
def self.defer_block(&blk)
f = Fiber.current
Expand Down Expand Up @@ -40,7 +50,7 @@ def self.each(list, concurrency = 1, &blk)
error = ex
end
end
if defined?(EM::Synchrony) && EM.reactor_running?
if Utils::ModuleLoaded.synchrony? && Utils::ModuleLoaded.fiberpool?
begin
result = EM::Synchrony::FiberIterator.new(list, concurrency).each(foreach)
rescue => ex
Expand Down Expand Up @@ -69,7 +79,7 @@ def self.map(list, concurrency = 1, &blk)
end
}.resume
end
if defined?(EM::Synchrony) && EM.reactor_running?
if Utils::ModuleLoaded.synchrony? && Utils::ModuleLoaded.fiberpool?
begin
result = EM::Synchrony::Iterator.new(list, concurrency).map(&foreach)
rescue => ex
Expand Down

0 comments on commit 8e56f20

Please sign in to comment.