Skip to content

Commit

Permalink
Set middleware_mutex when middleware/adapter classes are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Nov 13, 2019
1 parent 69f3078 commit d51a6c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def supports_parallel?

def inherited(subclass)
super
subclass.middleware_mutex
subclass.supports_parallel = supports_parallel?
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/faraday/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ def close
warn "#{@app} does not implement \#close!"
end
end

def self.inherited(subclass)
super
subclass.send(:load_error=, load_error) # DependencyLoader.inherited
subclass.middleware_mutex
end
end
end
8 changes: 7 additions & 1 deletion lib/faraday/middleware_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ module Faraday
# Adds the ability for other modules to register and lookup
# middleware classes.
module MiddlewareRegistry
def self.extended(klass)
super
klass.middleware_mutex
end

# Register middleware class(es) on the current module.
#
# @param autoload_path [String] Middleware autoload path
Expand Down Expand Up @@ -92,8 +97,9 @@ def lookup_middleware(key)
end

def middleware_mutex(&block)
puts "#{self}: middleware_mutex" if @middleware_mutex.nil?
@middleware_mutex ||= Monitor.new
@middleware_mutex.synchronize(&block)
@middleware_mutex.synchronize(&block) if block
end

def fetch_middleware(key)
Expand Down

0 comments on commit d51a6c6

Please sign in to comment.