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

#logger

Methods inherited from Base

#call

Constructor Details

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

Returns a new instance of Typhoeus.



17
18
19
20
21
# File 'lib/restify/adapter/typhoeus.rb', line 17

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

Instance Attribute Details

#syncObject (readonly)

Returns the value of attribute sync.



10
11
12
# File 'lib/restify/adapter/typhoeus.rb', line 10

def sync
  @sync
end

Instance Method Details

#call_native(request, writer) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/restify/adapter/typhoeus.rb', line 27

def call_native(request, writer)
  @mutex.synchronize do
    logger.debug { "[#{request.object_id}] Queue request #{request}" }
    @hydra.queue convert(request, writer)
    @hydra.dequeue_many
  end

  sync? ? @hydra.run : thread.run
end

#queued?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/restify/adapter/typhoeus.rb', line 37

def queued?
  @mutex.synchronize do
    @hydra.queued_requests.any? || @hydra.multi.easy_handles.count > 0
  end
end

#sync?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/restify/adapter/typhoeus.rb', line 23

def sync?
  @sync
end