Skip to content

Commit

Permalink
Use Async::Socket if is present
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeonfire committed May 22, 2024
1 parent 83b6ec7 commit 54519b2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/webmock/http_lib_adapters/async_http_client_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ def inspect

private

def socket_class
@_socket_class ||= Gem::Dependency.new("async-io").matching_specs.any? ? Async::IO::Socket : Socket
end

def create_connected_sockets
pair = begin
Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
socket_class.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
rescue Errno::EAFNOSUPPORT
Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM)
socket_class.pair(Socket::AF_INET, Socket::SOCK_STREAM)
end
pair.tap do |sockets|
sockets.each do |socket|
Expand Down

0 comments on commit 54519b2

Please sign in to comment.