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)


238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 238

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)


274
275
276
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 274

def alive?
  @thread.alive?
end

#closenil

Returns:

  • (nil)


259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 259

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)


255
256
257
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 255

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)


251
252
253
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 251

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