Class: Restify::Adapter::Typhoeus
- Includes:
- Logging
- Defined in:
- lib/restify/adapter/typhoeus.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Expect' => '', 'Transfer-Encoding' => '' }.freeze
- DEFAULT_OPTIONS =
{ followlocation: true, tcp_keepalive: true, tcp_keepidle: 5, tcp_keepintvl: 5 }.freeze
Instance Attribute Summary collapse
-
#sync ⇒ Object
readonly
Returns the value of attribute sync.
Instance Method Summary collapse
-
#call_native(request, writer) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
#initialize(sync: false, options: {}, **kwargs) ⇒ Typhoeus
constructor
A new instance of Typhoeus.
- #sync? ⇒ Boolean
Methods included from Logging
Methods inherited from Base
Constructor Details
#initialize(sync: false, options: {}, **kwargs) ⇒ Typhoeus
Returns a new instance of Typhoeus.
26 27 28 29 30 31 32 33 |
# File 'lib/restify/adapter/typhoeus.rb', line 26 def initialize(sync: false, options: {}, **kwargs) @sync = sync @hydra = ::Typhoeus::Hydra.new(**kwargs) @mutex = Mutex.new @signal = ConditionVariable.new @thread = nil @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#sync ⇒ Object (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 Metrics/AbcSize rubocop:disable Metrics/MethodLength
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/restify/adapter/typhoeus.rb', line 41 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
35 36 37 |
# File 'lib/restify/adapter/typhoeus.rb', line 35 def sync? @sync end |