Class: ReactOnRailsPro::RendererHttpClient::ConnectTimeoutWrapper

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

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.

Parameters:

  • connect_timeout: (Numeric, nil)
  • read_timeout: (Numeric, nil) (defaults to: nil)


75
76
77
78
79
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 75

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

Instance Method Details

#connect(remote_address, **options) ⇒ void

This method returns an undefined value.

Parameters:

  • remote_address (Object)
  • options (Object)


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

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