Skip to content

Commit 54519b2

Browse files
committed
Use Async::Socket if is present
1 parent 83b6ec7 commit 54519b2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/webmock/http_lib_adapters/async_http_client_adapter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ def inspect
152152

153153
private
154154

155+
def socket_class
156+
@_socket_class ||= Gem::Dependency.new("async-io").matching_specs.any? ? Async::IO::Socket : Socket
157+
end
158+
155159
def create_connected_sockets
156160
pair = begin
157-
Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
161+
socket_class.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
158162
rescue Errno::EAFNOSUPPORT
159-
Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM)
163+
socket_class.pair(Socket::AF_INET, Socket::SOCK_STREAM)
160164
end
161165
pair.tap do |sockets|
162166
sockets.each do |socket|

0 commit comments

Comments
 (0)