Class: Restify::Adapter::Typhoeus

Inherits:
Base
  • Object
show all
Includes:
Logging
Defined in:
lib/restify/adapter/typhoeus.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Expect' => '',
  'Transfer-Encoding' => ''
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#_fmt, #debug, #logger

Methods inherited from Base

#call

Constructor Details

#initialize(sync: false, **options) ⇒ Typhoeus

Returns a new instance of Typhoeus.



19
20
21
22
23
24
25
# File 'lib/restify/adapter/typhoeus.rb', line 19

def initialize(sync: false, **options)
  @sync   = sync
  @hydra  = ::Typhoeus::Hydra.new(**options)
  @mutex  = Mutex.new
  @signal = ConditionVariable.new
  @thread = nil
end

Instance Attribute Details

#syncObject (readonly)

Returns the value of attribute sync.



12
13
14
# File 'lib/restify/adapter/typhoeus.rb', line 12

def sync
  @sync
end

Instance Method Details

#call_native(request, writer) ⇒ Object

rubocop:disable AbcSize rubocop:disable MethodLength



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/restify/adapter/typhoeus.rb', line 33

def call_native(request, writer)
  req = convert(request, writer)

  if sync?
    req.run
  else
    @mutex.synchronize do
      debug 'request:add',
        tag: request.object_id,
        method: request.method.upcase,
        url: request.uri

      @hydra.queue(req)
      @hydra.dequeue_many

      thread.run unless thread.status
    end

    debug 'request:signal', tag: request.object_id

    @signal.signal
  end
end

#sync?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/restify/adapter/typhoeus.rb', line 27

def sync?
  @sync
end