Class: ReactOnRailsPro::RendererHttpClient::ConnectTimeoutWrapper

Inherits:
IO::Endpoint::Wrapper
  • Object
show all
Defined in:
lib/react_on_rails_pro/renderer_http_client.rb

Overview

Uses only public, documented Wrapper APIs (connect with timeout:, set_timeout) that have been stable since io-endpoint 0.15. No version pin needed —async-http’s own constraint (~> 0.14) governs the version.

Instance Method Summary collapse

Constructor Details

#initialize(connect_timeout:, read_timeout: nil) ⇒ ConnectTimeoutWrapper

Returns a new instance of ConnectTimeoutWrapper.



73
74
75
76
77
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 73

def initialize(connect_timeout:, read_timeout: nil)
  super()
  @connect_timeout = connect_timeout
  @read_timeout = read_timeout
end

Instance Method Details

#connect(remote_address, **options) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 79

def connect(remote_address, **options)
  socket = super(remote_address, **options.merge(@connect_timeout ? { timeout: @connect_timeout } : {}))
  set_timeout(socket, @read_timeout)

  return socket unless block_given?

  begin
    yield socket
  ensure
    socket.close
  end
end