Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set middleware_mutex when middleware/adapter classes are defined #1074

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def supports_parallel?

def inherited(subclass)
super
subclass.init_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.init_mutex
end
end
end
11 changes: 10 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.init_mutex
end

# Register middleware class(es) on the current module.
#
# @param autoload_path [String] Middleware autoload path
Expand Down Expand Up @@ -91,8 +96,12 @@ def lookup_middleware(key)
raise(Faraday::Error, "#{key.inspect} is not registered on #{self}")
end

def init_mutex
@middleware_mutex = Monitor.new
end

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

Expand Down