Class: ReactOnRailsPro::RendererHttpClient::PersistentThreadClient

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

Defined Under Namespace

Classes: ResponseEnvelope

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, protocol:, pool_limit:) ⇒ PersistentThreadClient

Returns a new instance of PersistentThreadClient.

Parameters:

  • endpoint: (Object)
  • protocol: (Object)
  • pool_limit: (Integer, nil)


181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 181

def initialize(endpoint:, protocol:, pool_limit:)
  @queue = Queue.new
  @ready = Queue.new
  @pending_results = {}.compare_by_identity
  @pending_results_mutex = Mutex.new
  @closed = false
  @closed_mutex = Mutex.new
  @thread = Thread.new { run_loop(endpoint:, protocol:, pool_limit:) }

  status, payload = @ready.pop
  raise payload if status == :error
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 217

def alive?
  @thread.alive?
end

#closenil

Returns:

  • (nil)


202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 202

def close
  result = nil
  @closed_mutex.synchronize do
    return if @closed

    @closed = true
    result = Queue.new
    @queue << [:close, result]
  end

  status, payload = wait_for_close_result(result)
  @thread.join
  raise payload if status == :error
end

#get(path, headers:) ⇒ Object

Parameters:

  • path (String)
  • headers: (Object)

Returns:

  • (Object)


198
199
200
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 198

def get(path, headers:)
  request(:get, path, headers:, body: nil)
end

#post(path, headers:, body:) ⇒ Object

Parameters:

  • path (String)
  • headers: (Object)
  • body: (Object)

Returns:

  • (Object)


194
195
196
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 194

def post(path, headers:, body:)
  request(:post, path, headers:, body:)
end